improve this sword fight bot -- Get the local player and their character local player =…
- User
improve this sword fight bot
-- Get the local player and their character local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait()
-- Wait for the necessary parts to load local humanoidRootPart = character:WaitForChild("HumanoidRootPart") local sword = character:WaitForChild("Linked Sword") local swordHandle = sword:WaitForChild("Handle") -- Get the sword's handle
local RunService = game:GetService("RunService") local pointingConnection
-- Variables to hold reach calculations local activationRange = 0 local armLength = 0 local swordLength = 0
-- Function to calculate the arm length local function calculateArmLength() armLength = 0
if character:FindFirstChild("RightUpperArm") then -- R15 Rig local upperArm = character:FindFirstChild("RightUpperArm") local lowerArm = character:FindFirstChild("RightLowerArm") local hand = character:FindFirstChild("RightHand") if upperArm and lowerArm and hand then armLength = upperArm.Size.Y + lowerArm.Size.Y + hand.Size.Y end elseif character:FindFirstChild("Right Arm") then -- R6 Rig local rightArm = character:FindFirstChild("Right Arm") if rightArm then armLength = rightArm.Size.Y end endend
-- Function to calculate the sword length local function calculateSwordLength() -- Get the largest dimension of the sword handle swordLength = math.max(swordHandle.Size.X, swordHandle.Size.Y, swordHandle.Size.Z) end
-- Function to calculate the total activation range local function calculateActivationRange() calculateArmLength() calculateSwordLength() local totalReach = armLength + swordLength activationRange = totalReach * 1.5 -- Adding a 10% buffer end
-- Function to find the nearest player local function findNearestPlayer() local closestDistance = math.huge local nearestPlayer = nil
for _, otherPlayer in pairs(game.Players:GetPlayers()) do if otherPlayer ~= player then local otherCharacter = otherPlayer.Character if otherCharacter then local otherHumanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart") if otherHumanoidRootPart then local distance = (humanoidRootPart.Position - otherHumanoidRootPart.Position).Magnitude if distance < closestDistance then closestDistance = distance nearestPlayer = otherPlayer end end end end end return nearestPlayerend
-- Rotate the character so the sword faces the nearest player and activate sword if in range local function pointSwordAtNearestPlayer() local nearestPlayer = findNearestPlayer() if nearestPlayer then local targetCharacter = nearestPlayer.Character local targetHumanoidRootPart = targetCharacter:FindFirstChild("HumanoidRootPart") if targetHumanoidRootPart and targetHumanoidRootPart.Parent.Humanoid and targetHumanoidRootPart.Parent.Humanoid.Health > 0 then -- Get the sword's position local swordPosition = swordHandle.Position
- Assistant