I have a question. So I need to script a anti-teleport script and I already scripted, but I’m not sure how “disable” it, when you are teleported back to the spawn:
local lastPosition = {}
local function newPlayer(plr)
plr.CharacterAdded:Connect(function(char)
lastPosition[plr.UserId] = nil
end)
spawn(function()
while true do
wait(1)
local char = plr.Character
if char ~= nil then
local humanoid = char:FindFirstChild("Humanoid")
if humanoid ~= nil and char.PrimaryPart ~= nil then
local currentPosition = char:GetPrimaryPartCFrame()
local tempLastPosition = lastPosition[plr.UserId]
if tempLastPosition ~= nil then
local beforePosition = Vector3.new(tempLastPosition.X, 0, tempLastPosition.Z)
local newPosition = Vector3.new(currentPosition.X, 0, currentPosition.Z)
local distance = (beforePosition - newPosition).Magnitude
local maxDistance = humanoid.WalkSpeed*2
if distance > maxDistance then
char:SetPrimaryPartCFrame(tempLastPosition)
continue
end
end
lastPosition[plr.UserId] = currentPosition
end
end
end
end)
end
players.PlayerAdded:Connect(newPlayer)
players.PlayerRemoving:Connect(remove)
for _, player in pairs(players:GetPlayers()) do
newPlayer(player)
end```