Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local localPlayer = Players.LocalPlayer
- local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local rootPart = character:WaitForChild("HumanoidRootPart")
- local function findNearestRootPart(pos)
- local nearest = nil
- local minDist = math.huge
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= localPlayer then
- local otherCharacter = player.Character
- if otherCharacter then
- local otherRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
- local otherHumanoid = otherCharacter:FindFirstChild("Humanoid")
- if otherRootPart and otherHumanoid and otherHumanoid.Health > 0 then
- local dist = (otherRootPart.Position - pos).Magnitude
- if dist < minDist then
- nearest = otherRootPart
- minDist = dist
- end
- end
- end
- end
- end
- return nearest
- end
- -- Function to make the character jump
- local function jump()
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
- end
- -- Coroutine for random jumping
- local function randomJumpCoroutine()
- while true do
- local waitTime = math.random(1, 5)
- task.wait(waitTime)
- jump()
- end
- end
- -- Start the random jumping coroutine
- task.spawn(randomJumpCoroutine)
- while true do
- local target = findNearestRootPart(rootPart.Position)
- if target then
- humanoid:MoveTo(target.Position)
- end
- task.wait(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment