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 teleportDistance = 4
- local player = game.Players.LocalPlayer
- local function distance(pos1, pos2)
- return (pos1 - pos2).magnitude
- end
- local function teleportAway(otherPosition)
- local direction = (player.Character.PrimaryPart.Position - otherPosition).unit
- local newPosition = otherPosition + direction * teleportDistance
- player.Character:SetPrimaryPartCFrame(CFrame.new(newPosition))
- end
- local function checkProximity()
- local myPosition = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position
- if not myPosition then return end
- for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
- if otherPlayer ~= player then
- local otherPosition = otherPlayer.Character and otherPlayer.Character.PrimaryPart and otherPlayer.Character.PrimaryPart.Position
- if otherPosition and distance(myPosition, otherPosition) < teleportDistance then
- teleportAway(otherPosition)
- end
- end
- end
- end
- RunService.Heartbeat:Connect(checkProximity)
- local Players = game:GetService("Players")
- local Character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
- local Torso = Character:WaitForChild("Torso")
- local proximityThreshold = 3 -- Adjust this value to set the distance threshold for triggering the anchor
- local function checkProximity()
- local closestPlayer = nil
- local minDistance = proximityThreshold
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= Players.LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
- local distance = (Torso.Position - player.Character.HumanoidRootPart.Position).magnitude
- if distance < minDistance then
- closestPlayer = player
- minDistance = distance
- end
- end
- end
- if closestPlayer then
- Torso.Anchored = true
- else
- Torso.Anchored = false
- end
- end
- while true do
- checkProximity()
- wait(0.1) -- Adjust this value as needed for the frequency of proximity checks
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement