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

Why won't this GUI textbutton script work?

Asked by 9 years ago

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

Log in to vote
2
Answered by 9 years ago

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)

0
Hey! Thanks for the great answer! I know it isn't my computer, because it worked before the last studio update. Antharaziia 75 — 9y
Ad
Log in to vote
0
Answered by
anerth 25
9 years ago

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)
0
The LocalScript is inside of a text button, which is inside a frame, which in inside screengui, which is in starter GUI Antharaziia 75 — 9y
Log in to vote
-2
Answered by 9 years ago

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

Answer this question