Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Player Teleportation only works in Studio?

Asked by 7 years ago

Hello, I'm trying to code a Player Teleportation script for an OnClicked Gui to teleport to my game. The code is below.

function OnClicked()
    script.Disabled = true
    local player = script.Parent.Parent.Parent.Parent
    if player then
        game:GetService("TeleportService"):Teleport(361416851, player)
    end
end

script.Parent.MouseButton1Click:connect(OnClicked)

Why does this not work in a game? If someone can help me, that'd be great!

0
Here is the game if you wanted to see it. https://www.roblox.com/games/723448353/test AdvancedCode 136 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You're trying to shut down the script before you can do anything. Move line 2 down to line 5 and it should work. Good luck!

1
I'd hate to say this but it still does not work and I have made sure the ID is correct. It says "Invalid Character to Teleport" in the Developer Console. Help again? AdvancedCode 136 — 7y
0
Okay, you may be using too many or too few .Parent's. Try subtracting one, and if that doesn't work, try adding one. ChipioIndustries 454 — 7y
1
I had to add a Parent! I appreciate this! AdvancedCode 136 — 7y
0
If it's a LocalScript (which it mostly should be for a gui) you can use "game.Players.LocalPlayer" anyhow. JJ_B 250 — 7y
0
@JJ_B LocalScripts don't allow for TeleportService. ChipioIndustries 454 — 7y
Ad

Answer this question