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

Clicking a textbutton to change properties?

Asked by 6 years ago

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)
0
Any errors? Gey4Jesus69 2705 — 6y
0
No, it says it should be running. noob1126 34 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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:

  1. 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 PlayerGui

  2. use :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.

  3. 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:

  1. When using :connect(function(), make sure connect has a capital C, a lower case c is deprecated.

  2. if the button is active or not will only affect the button if the button visibility is true.

  3. Use WaitForChild

  4. when a parent is loaded, all the childs are 100% loaded.

Good luck and have fun developing!

0
There are many spelling and grammar errors in here, so you may want to be go over your posts and fix any errors in the future. You can edit your own posts once they have been uploaded, also. TheDeadlyPanther 2460 — 6y
0
Sorry, I was busy speed writing. I'm only 9 so I'm still learning how to explain my stuff BlackOrange3343 2676 — 6y
0
Thanks for the help, I don't believe you're 9 though lol. noob1126 34 — 6y
0
I am 9 ._. BlackOrange3343 2676 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

0
What do you mean by player gui? Is it an object type or something under game? noob1126 34 — 6y
0
PlayerGui is an object inside each player that contains the currently visible GUI objects. TheDeadlyPanther 2460 — 6y

Answer this question