RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"rig that follows and attacks you when your in range and tell me where the script goes"
-- This script should go under the humanoid of the NPC you want to rig. local player = game.Players.LocalPlayer local humanoid = script.Parent local root = humanoid.Parent.PrimaryPart function findNearestPlayer() local playerList = Players:GetPlayers() local nearestPlayer = nil local distance = nil local direction = nil for _, player in pairs(playerList) do local character = player.Character if character then local distanceVector = player.Character.PrimaryPart.Position - root.Position if not nearestPlayer then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit elseif distanceVector.Magnitude < distance then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit end end end return nearestPlayer, distance, direction end RunService.Heartbeat:Connect(function() local nearestPlayer, distance, direction = findNearestPlayer() if nearestPlayer and distance < 10 then humanoid:Move(direction) local rarm = script.Parent:FindFirstChild("Right Arm") local larm = script.Parent:FindFirstChild("Left Arm") function dmg(hit) if hit.Parent ~= nil then local hum = hit.Parent:findFirstChild("Humanoid") if hum ~= nil then hum.Health = hum.Health -10 end end end rarm.Touched:connect(dmg) larm.Touched:connect(dmg) end end)