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)
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!
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.