Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService('Players')
- local Workspace = game:GetService('Workspace')
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local positions = {
- Vector3.new(21, 4, -433),
- Vector3.new(-47, 4, -434),
- Vector3.new(21, 4, -408),
- Vector3.new(-47, 4, -409)
- }
- local function walkToNearestPosition()
- if game.PlaceId ~= 14269621394 then
- return
- end
- local playerPosition = character.HumanoidRootPart.Position
- local nearestPosition = nil
- local minDistance = math.huge
- for _, pos in pairs(positions) do
- local distance = (pos - playerPosition).Magnitude
- if distance < minDistance then
- nearestPosition = pos
- minDistance = distance
- end
- end
- if nearestPosition then
- print("Moving to nearest position at: " .. tostring(nearestPosition))
- humanoid:MoveTo(nearestPosition)
- local moveToConnection
- moveToConnection = humanoid.MoveToFinished:Connect(function(reached)
- if reached then
- print("Player has reached the position!")
- moveToConnection:Disconnect()
- else
- print("Failed to reach the position. Trying again...")
- humanoid:MoveTo(nearestPosition)
- end
- end)
- else
- print("No valid positions found.")
- end
- end
- -- Call the function to move to the nearest position
- walkToNearestPosition()
Advertisement
Add Comment
Please, Sign In to add comment