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

Why does my teleport script work in the studio but not in the game?

I have a loading screen and when you click "Load Game" it should teleport you to a game. But the problem is, it gives me an error saying

"Invalid player to teleport" when I play it in game but when I try it in studio, it works perfectly fine

script

par = script.Parent.Parent
function onClicked()
	script.Parent:Destroy()
	par["Start Game"]:Destroy()
	par.ImageLabel.Image = "rbxgameasset://Images/Orange"
	game:GetService("TeleportService"):Teleport(961702140, game.Players.LocalPlayer)

end


script.Parent.MouseButton1Click:connect(onClicked)

2 comments

0

is it a local script?

0

oh wait.... XD it's a server script

2 answers

✓ Accepted answer

You do not need to add the game.Players.LocalPlayer . You could just use this in a LocalScript:

local par = script.Parent.Parent --Since this variable is used within a function, its best to add local to it.
script.Parent.MouseButton1Down:connect(function()
	script.Parent:Destroy()
	par["Start Game"]:Destroy()
  	par.ImageLabel.Image = "rbxgameasset://Images/Orange"
	game:GetService("TeleportService"):Teleport(961702140) --Notice the small change
end)

If this worked, please upvote and accept answer. If it didn't work, please comment. Thanks!

1 comment

0

game.Players.LocalPlayer is better to use then script.Parent.Parent becuase if you need help pro scripters will have no idea what the parent is or anything like that and its just a hasle to change if its in a diff child, so I would recomend using game.Players.LocalPlayer.

You should use an event. Not sure if you should make it a local script but here's the code.

Local par = script.Parent.Parent
Local plr = game.Players.LocalPlayer

Script.parent.MouseButton1Click:connect(function(click)

Script.Parent:Destroy()
Par["Start Game"]:Destroy()

par.ImageLabel.Image = "rbxgameasset://Images/Orange"

    game:GetService("TeleportService"):Teleport(961702140, plr)

End)

Try this and tell me if it doesn't work try adding game.Players.PlayerAdded:connect(function(plr) before the first event and removing the plr variable.

2 comments

0

Also make "End)" all lowercase

0

Your answer is error ridden. Please look it over and correct it.

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