Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local localPlayer = Players.LocalPlayer
- local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local rootPart = character:WaitForChild("HumanoidRootPart")
- local function hasItem()
- if character:FindFirstChildOfClass("Tool") then
- return true
- end
- local backpack = localPlayer:FindFirstChild("Backpack")
- if backpack and #backpack:GetChildren() > 0 then
- return true
- end
- return false
- end
- local function getClosestPlayer()
- local closestPlayer = nil
- local shortestDistance = math.huge
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= localPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
- local humanoid = player.Character:FindFirstChild("Humanoid")
- if humanoid and humanoid.Health > 0 then
- local distance = (rootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- closestPlayer = player
- end
- end
- end
- end
- return closestPlayer
- end
- local function moveToPlayer(targetPlayer)
- if not targetPlayer or not targetPlayer.Character then
- return
- end
- local targetPosition = targetPlayer.Character.HumanoidRootPart.Position
- humanoid:MoveTo(targetPosition)
- end
- RunService.Heartbeat:Connect(function()
- -- Comprobar si EnablePerseguirUsuario está habilitado
- if _G.EnablePerseguirUsuario and hasItem() then
- local closestPlayer = getClosestPlayer()
- if closestPlayer then
- moveToPlayer(closestPlayer)
- end
- end
- end)
- localPlayer.CharacterAdded:Connect(function(newCharacter)
- character = newCharacter
- humanoid = newCharacter:WaitForChild("Humanoid")
- rootPart = newCharacter:WaitForChild("HumanoidRootPart")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement