Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this teleport button only work in certain servers? The script seems to break.

The teleport only works at certain times. Sometimes, when I join the game, one of the teleports work (while the other one doesn't), sometimes, it's vice-versa. And even sometimes, when both are working, the script seems to break and stop functioning. It outputs no error. Why's this?

The script is the same for both teleports, but the position is different. One is 'Out' the other one is 'In' in line 10.

view source

	local debounce = false
	 
	script.Parent.Touched:Connect(function(hit)
	    if debounce == false then
	        debounce = true
	        if hit.Parent:FindFirstChild('Humanoid') then
	            local p = workspace[hit.Parent.Name]
	            local plr = game.Players:GetPlayerFromCharacter(p)
	            if plr.Stats.Level.Value >= 10 then
	                hit.Parent:MoveTo(game.Workspace['Boss Entrances'].DesertEntrance['Teleports'].Out.position)
	                print('teleported req')
	                wait(4)
	                debounce = false
	            end
	        end
	    end
	end)

1 answer

✓ Accepted answer

It seems to be that the main problem is where you've placed your debounce. Let's say the part was hit by something which isn't the player, then the script would run but it wouldn't set the debounce to false again. Same thing for if the player's level is below 10. Try this:

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if debounce == false then
        debounce = true
        if hit.Parent:FindFirstChild('Humanoid') then
            local p = workspace[hit.Parent.Name]
            local plr = game.Players:GetPlayerFromCharacter(p)
            if plr.Stats.Level.Value >= 10 then
                hit.Parent:MoveTo(game.Workspace['Boss Entrances'].DesertEntrance['Teleports'].Out.position)
                print('teleported req')
                wait(4)
            end
        end
	debounce = false
    end
end)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.