Hello! So I am trying to script an arcade game and am having a hard time with this script:
I want it when the player clicks the button, this frame appears visible but it isn’t working.
click.MouseClick:connect(function(player)
local gui = game.StarterGui.ScreenGui.Frame
gui.Visible = true
if true then
print("Visible!")
else
print("Not Visible!")
end
end)
I added a conditional statement and the output says visible, but it isn’t working. Anyone got any ideas?
click.MouseClick:connect(function(player)
local gui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame
gui.Visible = true
if gui.Visible == true then
print("Visible!")
else
print("Not Visible!")
end
end)
It looks like you’re setting the frame inside of the StarterGui to visible. If you want the player’s frame to become visible you can try finding the frame through the player’s PlayerGui. An example is below!
click.MouseClick:connect(function(player)
local gui = player.PlayerGui.ScreenGui.Frame -- Changed this!
gui.Visible = true
if true then
print("Visible!")
else
print("Not Visible!")
end
end)
You do need to fix something. You need to update the PlayerGui instead of the Starter Gui. Code examples above or just use this:
click.MouseClick:connect(function(player)
local gui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame
gui.Visible = true
if gui.Visible == true then
print("Visible!")
else
print("Not Visible!")
end
end)
Why is this?
Well, StarterGui holds GUI objects and LocalScripts. Children of this object are copied into the player’s PlayerGui when they spawn.
PlayerGuis hold the GUI objects that will be displayed to the player. If ScreenGui is a child of a PlayerGui, then any object inside of the ScreenGui will be drawn to the player’s screen. Any LocalScript will run as soon as it is inserted into a PlayerGui. Meaning, if the script isn’t in the UI itself, then the UI must be edited using the PlayerGui.
Hey man! Thanks a lot. It finally works now, thanks for the help. It means a lot to me. I found an answer that works thanks to you. Fast and easy explanation.