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

[UNSOLVED]GUI Text Button click, makes stuff visible and changes text?

Asked by 9 years ago

So basically I am making a car shop GUI shown here(http://prntscr.com/6bx9ln). I have the main GUI with all the buttons and then there is a information panel GUI on the right. When someone clicks on a car text button I have a text button named "Name" and a text button called "Buy". The text button called "Name" is supposed to be the name of the car in the information panel, and in the script I want the script to change the text button "Name" 's text from "Name" to the car name. Keep in mind that "Name" and "Buy" are both invisible. For "Buy", I want that to also become visible when the player clicks on a car text button and I have the "Buy" text button's text change from Buy to the price of the car and making it visible when they click a car text button. I have made this script and It is not working.

script.Parent.MouseButton1Click:connect(function()
 local x = StarterGui.Carshop.Frame  --the variable
 x.Name.Visible = true --making the text button "name" visible
 x.Buy.Visible = true --making the text button "buy" visible
 x.Buy.Text = "$5000" --Changing the text from "buy" to $5000
 x.Name.Text = "Civi Car" --Changing the text from "Name" to Civi Car"
 end)

If you want to see the web or layout of the GUI and frame it is here http://prntscr.com/6byc60.

Also In my last post, someone tried fixing it and it still didn't work(thanks tho BSI).

PS: I might not respond right away.

4 answers

Log in to vote
1
Answered by
yumtaste 476 Moderation Voter
9 years ago
script.Parent.MouseButton1Click:connect(function()
 local x =   --I can't view the image, so can someone please comment the correct hierarchy?
 x:FindFirstChild("Name").Visible = true
 x:FindFirstChild("Buy").Visible = true 
 x:FindFirstChild("Buy").Text = "$5000
 x:FindFirstChild("Name").Text = "Civi Car"
 end)

Someone in the comments please explain the hierarchy since I can't view it at the moment. FindFirstChild might help, and I don't have much time to explain, just try this code after someone puts in the hierarchy.

Ad
Log in to vote
1
Answered by
Dr_Doge 100
9 years ago

This might be because the StarterGui and the PlayerGui are different. The PlayerGui is a Gui that each separate player sees and has, and the StarterGui is the... Main copy that roblox clones into each and every new players PlayerGui.

If you used the Global Variable "Parent" this would be alot simpler.

script.Parent.Parent.Buy -- The Script will automatically know that you are talking about it when you use the word script

A Parent is above the Child. In this scenario script is the Child of "Civi Car" and "Civi Car" Is the Parent of script.

PS: Its ok PPS: I would like to see this game you are making... my username is fancyboby47 and I would like it if you msg-ed me a link to this game. You dont have to...

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

fancyboy is on the right track, but he missed the most obvious problem: Objects have a Name property, so you can't use x.Name to get the Name button. You either have to rename the button, or access it like so: x:FindFirstChild("Name").

You can't modify the StarterGui and have it effect the current Player's GUI. You have to set x to the Carshop.Frame that is located within the PlayerGui of the current player, which you can get either for the script reference: script, or from Game.Players.LocalPlayer.

Log in to vote
0
Answered by 9 years ago

Try this

script.Parent.MouseButton1Click:connect(function()
 local x = script.Parent.Parent  --the variable
 x.Name.Visible = true --making the text button "name" visible
 x.Buy.Visible = true --making the text button "buy" visible
 x.Buy.Text = "$5000" --Changing the text from "buy" to $5000
 x.Name.Text = "Civi Car" --Changing the text from "Name" to Civi Car"
 end)

Answer this question