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

Why won't this GUI textbutton script work?

Hello again! So, this Localscript is inside of a textbutton. When clicked, it is supposed to close startscreen (a frame) and open Step1 (another frame) Can you guys help me with why it won't work? I cannot use the output, because when I click 'Run' or 'Play Solo' my studio crashes :/

local startscreen = game.Players.LocalPlayer.PlayerGui.ScreenGui.startscreen
local step = game.Players.LocalPlayer.PlayerGui.ScreenGui.Step1

script.Parent.MouseButton1Click:connect(function()
    startscreen.Visible = false
    step.Visible =  true
end)

3 answers

✓ Accepted answer

This may or may not work depending on if your hierarchies are correct. If studio is crashing, it may be a bug with your computer. The local keyword is not necessary with variables that are not within a specific scope. Also, I recommend using wait(1) at the beginning of all localscripts so that you can guarantee that the character's assets are loading before you try modifying them.

wait(1)
player = game.Players.LocalPlayer
gui = player.PlayerGui.ScreenGui
startscreen = gui.startscreen
step = gui.Step1

script.Parent.MouseButton1Down:connect(function()
    startscreen.Visible = false
    step.Visible =  true
end)

1 comment

0

Hey! Thanks for the great answer! I know it isn't my computer, because it worked before the last studio update.

One thing. Where are you putting the script? With the gui, or in the workspace, or other place?

ok so I got the info, and I am ready to start.

wait(1)
-- has to load... then!
local startscreen = game.Players.LocalPlayer.PlayerGui.ScreenGui.startscreen
local step = game.Players.LocalPlayer.PlayerGui.ScreenGui.Step1
 
script.Parent.MouseButton1Click:connect(function()
--THE MISTAKES!
    -- startscreen.Visible = false
--should be
startscreen.BackgroundTransparency = 1
--MORE MISTAKES!
    --step.Visible =  true
--should be
step.BackgroundTransparency = 1
--Done
end)

1 comment

0

The LocalScript is inside of a text button, which is inside a frame, which in inside screengui, which is in starter GUI

You set your GUI hierarchy incorrectly. LocalPlayer would not be inside StarterGui.

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