Assistance with Teleport

Hello, i just added this script to my game to control teleports or increased walk speed exploits in ServerScriptService

game.Players.PlayerAdded:Connect(function(player) --Referencing the player
	local character = player.Character

	player.CharacterAdded:Connect(function(character) --This function is called on every spawn
		local hum = character.Humanoid
		local character = player.Character
		local rootPart = character.HumanoidRootPart

		--AntiSpeed
		wait(5)
		while true do
			local Pos1 = rootPart.Position
			wait(0.1)
			local Pos2 = rootPart.Position
			local difference = ((Pos1 - Pos2) * Vector3.new(1, 0, 1)).Magnitude

			if difference > 12 then --Difference between original and new position on studs
				rootPart.Position = Pos1
			end
		end
	end)
end)

My problem is i also have a teleport between 2 doors in my game. But now that i added the antiexploit script the doors cant teleport. So im thinking on how to fix it, maybe making the door disable the antiexploit during the teleport? but i dont know how to reference and disable the antiexploit located in ServerScriptService. PD: the doors that teleport are a model in workspace that use a script.
This is the door script:

-- Variables
local TeleportDoorEvent = game.ReplicatedStorage.TeleportDoorEvent

local Door1 = script.Parent.TeleportDoor1 -- Depends on what the name, if your name is different than change to your name
local Door2 = script.Parent.TeleportDoor2

local debounce = false -- Cooldown

-- Main

-- Door 1
Door1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true

			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr then
				TeleportDoorEvent:FireClient(plr) -- Firing Clients
				wait(0.8)
				hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
				wait(2)
				debounce = false
			end
		end
	end
end)

-- Door 2
Door2.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true

			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr then
				TeleportDoorEvent:FireClient(plr) -- Firing Clients
				wait(0.8)
				hit.Parent.HumanoidRootPart.CFrame = Door1.CFrame
				wait(2)
				debounce = false
			end
		end
	end
end) -- End

Thanks!

I don’t recommend disabling it but instead create a check within the anti-exploit to see if the player has used a door recently or not.

You should add a value to the character called like “Teleporting” when they are about to change positions in the door script and then add a line to the script that checks if the player has the value and if it does then the anti cheat doesn’t count it as exploiting for a second would look something like this -

game.Players.PlayerAdded:Connect(function(player) --Referencing the player
	local character = player.Character

	player.CharacterAdded:Connect(function(character) --This function is called on every spawn
		local hum = character.Humanoid
		local character = player.Character
		local rootPart = character.HumanoidRootPart

		--AntiSpeed
		wait(5)
		while true do
           if character:FindFirstChild("Teleporting") == nil then
			local Pos1 = rootPart.Position
			wait(0.1)
			local Pos2 = rootPart.Position
			local difference = ((Pos1 - Pos2) * Vector3.new(1, 0, 1)).Magnitude

			if difference > 12 and character:FindFirstChild("Teleporting") == nil then --Difference between original and new position on studs
				rootPart.Position = Pos1
			end
            end
		end
	end)
end)

Door scripts would look like this -

-- Variables
local TeleportDoorEvent = game.ReplicatedStorage.TeleportDoorEvent

local Door1 = script.Parent.TeleportDoor1 -- Depends on what the name, if your name is different than change to your name
local Door2 = script.Parent.TeleportDoor2

local debounce = false -- Cooldown

-- Main

-- Door 1
Door1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true

			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr then
				TeleportDoorEvent:FireClient(plr) -- Firing Clients
				wait(0.8)
                local Teleporting = Instance.new("BoolValue",hit.Parent)
                Teleporting.Name = "Teleporting"
                game.Debris:AddItem(Teleporting,1)
				hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
				wait(2)
				debounce = false
			end
		end
	end
end)

-- Door 2
Door2.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true

			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr then
				TeleportDoorEvent:FireClient(plr) -- Firing Clients
				wait(0.8)
                local Teleporting = Instance.new("BoolValue",hit.Parent)
                Teleporting.Name = "Teleporting"
                game.Debris:AddItem(Teleporting,1)
				hit.Parent.HumanoidRootPart.CFrame = Door1.CFrame
				wait(2)
				debounce = false
			end
		end
	end
end) -- End

I believe it should work out now :slight_smile:

1 Like

I see, that makes sense. I tried implementing it and it allows me to teleport yey! only problem now is that after using the door if i put my walkspeed to 100 for example, the antiexploit script seems to stay off since it no longers detects me and returns me to pos1