Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the teleport function
- local function teleportToPlayer(targetPlayer)
- local distance = (targetPlayer.Character.HumanoidRootPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
- local tweenInfo = TweenInfo.new(distance/100, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
- local tween = game:GetService("TweenService"):Create(game.Players.LocalPlayer.Character.HumanoidRootPart, tweenInfo, {CFrame = targetPlayer.Character.HumanoidRootPart.CFrame - targetPlayer.Character.HumanoidRootPart.CFrame.LookVector * 3})
- tween:Play()
- end
- -- Define the loop function
- local function loopTeleport()
- local nearestPlayer = nil
- local nearestDistance = math.huge
- -- Find the nearest player
- for _, player in pairs(game.Players:GetPlayers()) do
- if player ~= game.Players.LocalPlayer then
- local distance = (player.Character.HumanoidRootPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
- if distance < nearestDistance then
- nearestPlayer = player
- nearestDistance = distance
- end
- end
- end
- -- Teleport to the nearest player
- if nearestPlayer then
- teleportToPlayer(nearestPlayer)
- end
- end
- -- Start the loop
- local toggleValue = false
- local toggleButton = nil
- spawn(function()
- while true do
- if toggleValue then
- loopTeleport()
- end
- wait(0)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment