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

Gui works in studio but in game?

local i = script.Parent
local map = workspace.Stadium.sa
local gui = script.Parent.Parent.Parent
local tele1 = game.Lighting.Tele1
function onButtonClicked()
    local plr = game.Players.LocalPlayer
    local character = plr.Character
if (plr and character ~= nil) then
	character:MoveTo(map.Position)  
    tele1:Clone().Parent = plr.PlayerGui
	script.Parent.Parent.Parent:Destroy()
end
    end
i.MouseButton1Down:connect(onButtonClicked)

I've re wrote it countless times, I browsed the wiki, This is my last resort! Thanks for any help.

1 comment

0

Is it in a LocalScript?

2 answers

✓ Accepted answer
repeat wait() until game.Players.LocalPlayer
local i = script.Parent
local map = workspace.Stadium.sa
local gui = script.Parent.Parent.Parent
local tele1 = game.Lighting.Tele1
function onButtonClicked()
    local plr = game.Players.LocalPlayer
    local character = plr.Character
if (plr and character ~= nil) then
    character:MoveTo(map.Position)  
    tele1:Clone().Parent = plr.PlayerGui
    script.Parent.Parent.Parent:Destroy()
end
    end
i.MouseButton1Down:connect(onButtonClicked)

The difference between studio and in game mode is that in studio, the player loads immediately. In game, the player takes a little bit to load. So, if we keep waiting until the script detects a Player, this can be resolved.

2 comments

0

Remember to mark as answer if it works.

0

Thanks,

Is it in a local script?

1 comment

0

Please refrain from asking questions in answers. These belong inside the comments to the question.

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