My (almost "impenetrable") Anti-Teleport System

I’m developing a game (it would be something like a SuperMarioWorld) when it came to my mind that Exploiters could teleport freely if they found out the coordinates of each place in the game. So, with the help of @Clear_View,I developed an almost “impenetrable” system (for a map that has teleporters)

I would like a feedBack on my system

The idea is as follows: When a player is playing normally (without touching any teleporter) if a calculation (which takes an old position and calculates the difference between a second new position for this player) is greater than x, this player will be kicked.

However, we cannot forget the teleporters that exist on the map. Whenever the player touches one of them, another script connects with the Main (which makes the calculation mentioned)
and leave a key, say, “Active” so that this player is not kicked, that is, it warns the main script not to kick it, as it is teleporting with a legal game teleportation system.

  • right, but what’s so special about it?

usually what is thought is that an Exploiter could teleport at the same time that it touches a teleporter, since he would be totally free of any punishment, correct?
Well, thinking about it, I implemented another check the moment he touches this Teleporter (from the map) who checks if in that short time he is free of any punishment, he teleports.

in other words, in short, there is almost no way for someone to teleport without being punished with this system (according to what was tested).

  • Now we arrive at the only and most fatal problem of this system (which does not happen because of it):The High Ping :frowning:

Yes, this system is beautiful, but a single error completely compromises it

I will show you the script that I created so that everything I mentioned happens:
PrincipalScript: responsible for doing the main verification

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()	

local canTP = false
local teleportoworld = false

local oldPositions = {} 

local tpThreshold = 50 

local armazem = nil
local armazemw = nil

local recent = nil

--main event to warn this script that the player has teleported with a map teleport
>game:GetService"ServerStorage".canteleport.Event:connect(function(namer)    
end)


--main script check
while wait(2) do
    local newPlrTable = {}
  	 local plr = player
        local playerTable = nil
        
       
        for x,v in pairs(oldPositions) do
            if (v[1] == plr.Name) then
                playerTable = v

                break;
            end
        end

        
        if (playerTable) then
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character.Humanoid.Health > 0 then           
local oldPos = playerTable[2]
            local dPos = (Vector3.new(game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.X,0,game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.Z) -oldPos).magnitude
			print(dPos)           
 if (dPos > tpThreshold) and (not canTP) and (not teleportoworld) then
				if (recent == nil) then 
                warn(playerTable[1].." probably just teleported")
				plr:Kick("Teleport")
				end
               
            
        end
if (recent == true) then recent = nil end
end
end
       if not plr.Character:FindFirstChild("HumanoidRootPart") or plr.Character.Humanoid.Health == 0 then
	plr.CharacterAdded:Wait()
	print("só esperei renacser")
end
        local newPlayerInfo = {plr.Name, Vector3.new(plr.Character.HumanoidRootPart.Position.X,0,plr.Character.HumanoidRootPart.Position.Z)}

        
        table.insert(newPlrTable, newPlayerInfo)
    
print("magnitude")
 
    oldPositions = newPlrTable
end
end)

see it working:

as shown, it seems to be perfect, but it only takes a player with a high ping to spoil it:


why does this happen? the answer is below:

for the server, for some reason (it is not the script that does this) the player returns to the position before being teleported and returns again to the defined coordinate. This generates a “False Positive” (the script takes his new position ( in this case, the one when he returns to the teleport) and the old one (to which the teleporter sends the player)

unfortunately this seems to be some bug or glitch (I’m not sure, I’m not an expert on that).

But then, what did you think of this system? do you think there is something I should change or something, maybe a tip? I want your FeedBack!

I will leave the two scripts mentioned below:

PrincipalScript:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()	

local canTP = false
local teleportoworld = false
local levelmaxmag = 0

local oldPositions = {} 

local tpThreshold = 50 

local armazem = nil
local armazemw = nil

local recent = nil


game:GetService"ServerStorage".canteleport.Event:connect(function(namer)    
if namer == player.Name then
if armazemw ~= player.Name then
print("recebido")
armazemw = player.Name
canTP = true
local count = 0
local timecooldown = 20
print(tostring(canTP).. " True")
local oldpos = {}		
	while wait(0.5) do
if count == 5 then break end    
print(player.Character.HumanoidRootPart.Position)
local newPlrTable = {}
count = count + 1  	
 local plr = player
        local playerTable = nil
        
       
        for x,v in pairs(oldpos) do
            if (v[1] == plr.Name) then
                playerTable = v

                break;
            end
        end

        
        if (playerTable) then
if plr.Character:FindFirstChild("HumanoidRootPart") then           
local oldPosition = playerTable[2]
print(oldPosition)
            local dPos = (Vector3.new(game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.X,0,game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.Z) -oldPosition).magnitude
			print(dPos)
            if (dPos > timecooldown) and  (not teleportoworld) then
				
                warn(playerTable[1].." probably just teleported in TeleporterCooldownTime")
				plr:Kick("Teleport")
               
            
        end
end
end
       if not plr.Character:FindFirstChild("HumanoidRootPart") then
	plr.CharacterAdded:Wait()
	print("só esperei renacser no coolddown")
end
        local newPlayerInfo = {plr.Name, Vector3.new(plr.Character.HumanoidRootPart.Position.X,0,plr.Character.HumanoidRootPart.Position.Z)}

        print(newPlayerInfo[2])
        table.insert(newPlrTable, newPlayerInfo)
     
    oldpos = newPlrTable
end
recent = true
    canTP = false
print(tostring(canTP).." false")
armazemw = nil
end
end
end)




while wait(2) do
    local newPlrTable = {}
  	 local plr = player
        local playerTable = nil
        
       
        for x,v in pairs(oldPositions) do
            if (v[1] == plr.Name) then
                playerTable = v

                break;
            end
        end

        
        if (playerTable) then
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then           
local oldPos = playerTable[2]
            local dPos = (Vector3.new(game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.X,0,game.Players:FindFirstChild(playerTable[1]).Character.HumanoidRootPart.Position.Z) -oldPos).magnitude
			print(dPos)           
 if (dPos > tpThreshold) and (not canTP) and (not teleportoworld) then
				if (recent == nil) then 
                warn(playerTable[1].." probably just teleported")
				plr:Kick("Teleport")
				 
					
				end
               
            
        end
if (recent == true) then recent = nil end
end
end
       if not plr.Character:FindFirstChild("HumanoidRootPart") then
	plr.CharacterAdded:Wait()
	
end
        local newPlayerInfo = {plr.Name, Vector3.new(plr.Character.HumanoidRootPart.Position.X,0,plr.Character.HumanoidRootPart.Position.Z)}

        
        table.insert(newPlrTable, newPlayerInfo)
    
print("magnitude")
 
    oldPositions = newPlrTable
end
end)

script that connects to PrincipalScript and alerts you when the player touches a teleporter:


local pos1 = Vector3.new(workspace.teleporter.Position.X,0,workspace.teleporter.Position.Z)
print((pos1 - Vector3.new(100,0,20)).Magnitude )

local armazem
game.Workspace.teleporter.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if armazem ~= hit.Parent.Name then
		game.ServerStorage.canteleport:Fire(hit.Parent.Name)
		
		hit.Parent.HumanoidRootPart.Position = Vector3.new(100,20,0)
		
		wait(0.3)
		armazem = nil
		end
	end
end)

Rather than having this, why not load and delete the wanted map from storage every time player finishes a level?
You won’t have to check for Anything, and it’s much easier for your game to work (if character goes around 50-100k studs from place origin in 3D space roblox starts to break down; you can try this in studio)

I believe Nintendo probably does this too, since it’s easy for a game to handle less objects existing in map at same time! Hackers won’t be able to do anything either

I bypassed it quite easily, but you can fix it as quickly.
The issue you have is the fact you used a while loop and missed a check, because when a while loop errors the script stops running it.
Around line 38, your if statement checks plr.Character.Humanoid.Health > 0 and you didnt confirm if Humanoid was nil with a :FindFirstChild() check beforehand, so an exploiter can delete the humanoid by doing game.Players.LocalPlayer.Character.Humanoid:Destroy() (this does replicate to the server) and once it respawns you, the script errors and your teleport system is defeated.