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

Teleport script spams console and takes forever to teleport?

So i built a teleport script which is in a localscript which is in a GUI at the moment. However to takes forever to be teleported. My console gives me "bad request" errors and they never end until I am teleported. As well as the fact that sometimes the game I want to be teleported to crashed. I wanted to know if there was a better way or more stable way to use this teleport script. I sat once for 3 minutes till the script finally teleported me. Exuse my lack of teleporting players to different games knowledge I just started this.

player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:connect(function()
    game:GetService("TeleportService"):Teleport(334747890, player)
end)

1 answer

✓ Accepted answer

I think you defined player wrong. The easiest way I find to define the player is instead of local player, I use

player = script.Parent.Parent.Parent.Parent.Parent

So, I would try to use

player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Down:connect(function()
    game:GetService("TeleportService"):Teleport(334747890, player)
end)

And the reason for your spam was due to you defining player wrong. If you use local player, the game must search for it, taking longer. Meaning you should always use the defining method I used.

player = script.Parent.Parent.Parent.Parent.Parent

3 comments

0

The script should not be having to look for LocalPlayer, it's a property for Players that gets set for each client. I do not see why the user's script was not working, however you should not have to use multiple parents just to find the player in a local script.

0

Sorry for doing it the way I was taught..

1

You were poorly taught. Teaching other people hacky and horrid ways rather than making a suitable solution is wrong. The only way I think of possibly fixing it is adding a "local" before the variable to push it to the top of the stack.

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