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

Clicking a textbutton to change properties?

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)

2 comments

0

Any errors?

0

No, it says it should be running.

2 answers

✓ Accepted answer

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
  1. 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.
  1. 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.
  1. if the button is active or not will only affect the button if the button visibility is true.
  1. Use WaitForChild
  1. when a parent is loaded, all the childs are 100% loaded.

Good luck and have fun developing!

4 comments

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.

0

Sorry, I was busy speed writing. I'm only 9 so I'm still learning how to explain my stuff

0

Thanks for the help, I don't believe you're 9 though lol.

0

I am 9 ._.

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.

2 comments

0

What do you mean by player gui? Is it an object type or something under game?

0

PlayerGui is an object inside each player that contains the currently visible GUI objects.

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