I'm making a shop gui, and I wan't to make it so that when a certain button is clicked, all the properties I want changed get changed. This is what I have so far, and it's not making the buttons visible and active.
local button = script.Parent local a = 0 local ob = game.StarterGui.Shop.OpenShop.ActualOpen.Buttons button.MouseButton1Click:connect(function() ob.Close.Active = true ob.Close.Visible = true ob.Gamepases.Active = true ob.Gamepases.Visible = true ob.SlightSpeedBoost.Active = true ob.SlightSpeedBoost.Visible = true ob.Skip1Level.Active = true ob.Skip1Level.Visible = true ob.Skip3Levels.Active = true ob.Skip3Levels.Visible = true ob.Tips.Active = true ob.Tips.Visible = true end)
The answer above is correct, but it's not well explained and he also used :FindFirstChild() incorrectly.
Here is a few notes you should read:
Do not use
FindFirstChild
for any game service. Especially PlayerGui. When the player join's the PlayerGui is 100% inside of the player. And whatever is in StarterGui Is cloned into the PlayerGuiuse
:WaitForChild()
in variables, WaitForChild waits for a certain object to load in. With a variable that Contain's WaitForChild. It will help the system find the objects. Without :WaiTForChild, it may work in studio but not in game and will nil the objects.You DO NOT Need to set a button active or not. If the visibility of the button is false, it won't fire on click.
Study those notes, now here's a fix;
MAKE SURE THIS IS A LocalScript
local button = script.Parent local a = 0 local plr = game.Players.LocalPlayer -- the player local ob = plr.PlayerGui:WaitForChild('Shop').OpenShop.ActualOpen.Buttons -- waitforchild button.MouseButton1Click:Connect(function() ob.Close.Visible = true ob.Gamepases.Visible = true ob.SlightSpeedBoost.Visible = true ob.Skip1Level.Visible = true ob.Skip3Levels.Visible = true ob.Tips.Visible = true end)
Make sure all the buttons have there active set to True. This won't effect the buttons.
Lastly a few more notes to study:
When using :connect(function(), make sure connect has a capital C, a lower case c is deprecated.
if the button is active or not will only affect the button if the button visibility is true.
Use WaitForChild
when a parent is loaded, all the childs are 100% loaded.
Good luck and have fun developing!
The problem is that you are using the StarterGui, you need to use the PlayerGui. I assume this is in a local script.
add this line to your code in the beginning
local player = game.Players.LocalPlayer local playergui = player:FindFirstChild("PlayerGui")
then change the local ob to
local ob = playergui.Shop.OpenShop.ActualOpen.Buttons
The StarterGui is just used to give the gui when player join/respawn the game.