Issues with my Teleport Service

Disclaimer: I am only a beginner and Teleporting players seems to be my weakness.

Hi,
I am having trouble with my teleporter. If you walk through the teleporter and continue walking once you arrive, it turns into an endless loop. I wrote in the script that you need to teleport players 4 studs away to avoid this.

My Script
local TeleportPad1 = script.Parent.TeleportPad1

local TeleportPad2 = script.Parent.TeleportPad2

TeleportPad1.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild(“HumanoidRootPart”) then

hit.Parent.HumanoidRootPart.CFrame = TeleportPad2.CFrame + TeleportPad2.CFrame.LookVector * 4 – Telepports the player a few studs away from the part, so it doesn’t result in spam teleporting.

end

end)

TeleportPad2.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild(“HumanoidRootPart”) then

hit.Parent.HumanoidRootPart.CFrame = TeleportPad1.CFrame + TeleportPad1.CFrame.LookVector * 4 – Telepports the player a few studs away from the part, so it doesn’t result in spam teleporting.

end

end)

Can anyone help? Thanks.

I don’t know how to use the code format

2 Likes

Code format is just putting ```
before and after the lines. It really helps to read it.

What error does this throw?

1 Like

It doesn’t show an error. It’s just something that’s inconvenient.

I think what you did is actually the solution to the initial problem? What seems to be the issue now? Players get teleported with an offset so there should be no spam teleporting.

Sorry, if I did not understand that correctly :frowning:

Just debounce it.
Set a variable boolean to true and then back to false at the end after a cooldown.
If the boolean is ‘true’ dont run the function.

1 Like

How do you do that? :weary: (Once again I am new and i’m only just learning) I don’t know what a boolean is.

1 Like

What’s the point? There is no bug if it teleports with an offset.

Everyone, I’m sending a video of what happens.

1 Like

Thanks. Because I still can’t get it…

It could look something like:

local TeleportPad1 = script.Parent.TeleportPad1
local TeleportPad2 = script.Parent.TeleportPad2

local debounce = false

TeleportPad1.Touched:Connect(function(hit)
    if debounce then return end
    debounce = true
    if hit.Parent:FindFirstChild(“HumanoidRootPart”) then
        hit.Parent.HumanoidRootPart.CFrame = TeleportPad2.CFrame + TeleportPad2.CFrame.LookVector * 4 – Telepports the player a few studs away from the part, so it doesn’t result in spam teleporting.
    end
    wait(3) -- cooldown time
    debounce = false
end)

TeleportPad2.Touched:Connect(function(hit)
    if debounce then return end
    debounce = true
    if hit.Parent:FindFirstChild(“HumanoidRootPart”) then
        hit.Parent.HumanoidRootPart.CFrame = TeleportPad1.CFrame + TeleportPad1.CFrame.LookVector * 4 – Telepports the player a few studs away from the part, so it doesn’t result in spam teleporting.
    end
    wait(3) -- cooldown time
    debounce = false
end)

Here. (The game isn’t supposed to look like this, I am just testing the teleporters out.)
robloxapp-20210219-1310280.wmv (1.8 MB)

1 Like

Debounce will fix this. Try the method I showed you above.

Ah, I see now. The issue is that the offset is too small. Try increasing it so the character actually gets teleported away from the 2nd teleporter.

hit.Parent.HumanoidRootPart.CFrame = TeleportPad2.CFrame + TeleportPad2.CFrame.LookVector * [try to put a higher number here]

Also, move teleporters away from each other because they are just too close.

I know, it was just for testing.

Okay, I’ll try this now. One minute.

2 Likes

@UfoVR1337 Okay, I tried this and put the teleporters further apart. It still does it but you just need to walk a bit further. @Self_Reflexive I put local debounce = false at the beginning but nothing happened.

1 Like

Did you set debounce within the functions?

Teleport service does not have anything to do with your script.

Also I suggest you do not set the CFrame. Use :MoveTo(POS)

Anyways here would be the correct script to do this.

local TeleportPad1, TeleportPad2  = script.Parent:WaitForChild("TeleportPad1"), script.Parent:WaitForChild("TeleportPad2")
local Debounce1, Debounce2 = false, false
local HitDebounce = {}


TeleportPad1.Touched:Connect(function(Hit)
	if not Debounce1 and not HitDebounce[Hit.Parent] and Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChildOfClass("Humanoid") then
		HitDebounce[Hit.Parent] = Hit.Parent
		Debounce1 = true

		Hit.Parent:MoveTo(TeleportPad2.Position + Vector3.new(0, 3, 0))

		wait(.1)
		Debounce1 = false
		wait(2)
		HitDebounce[Hit.Parent] = nil
	end
end)

TeleportPad2.Touched:Connect(function(Hit)
	if not Debounce2 and not HitDebounce[Hit.Parent] and Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChildOfClass("Humanoid") then
		HitDebounce[Hit.Parent] = Hit.Parent
		Debounce2 = true

		Hit.Parent:MoveTo(TeleportPad1.Position + Vector3.new(0, 3, 0))

		wait(.1)
		Debounce2 = false
		wait(2)
		HitDebounce[Hit.Parent] = nil
	end
end)

If you give me some time I could try to code it myself.

Sounds reasonable, Let me try this.

1 Like