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

How do i get this button script with local variables working again?

Asked by 5 years ago

Hello, I made a script short ago which would show a gui. It worked. This is the script that worked:

01script.Parent.OpenedStoreFrame.BackgroundTransparency = 1
02function leftClickopenStore()
03    if script.Parent.OpenedStoreFrame.BackgroundTransparency == 1 then
04        print("BGTransparency to 0")
05        script.Parent.OpenedStoreFrame.BackgroundTransparency = 0
06    elseif script.Parent.OpenedStoreFrame.BackgroundTransparency == 0 then
07        script.Parent.OpenedStoreFrame.BackgroundTransparency = 1
08        print ("BGTransparency to 1")
09    end
10end
11 
12 
13script.Parent.StoreFrame.StoreButton.MouseButton1Click:Connect(leftClickopenStore)

Then, my friend told me i could do it on a more easy way. I remade the script, but with a specific close button. First the open button was also the close button. But this script didnt work:

01-- Defines GUI objects of store --
02local OpenedStoreFrame = script.Parent.OpenedStoreFrame
03local StoreText = script.Parent.OpenedStoreFrame.TextLabel
04local CloseButton = script.Parent.OpenedStoreFrame.CloseButton
05local VipGamepassIcon = script.Parent.OpenedStoreFrame.VipGamepass
06local StoreOpenButton = script.Parent.StoreFrame.StoreButton
07-- Makes store gui objects invisible at start of game --
08OpenedStoreFrame.Visible = false
09StoreText.Visible = false
10CloseButton.Visible = false
11VipGamepassIcon.visible = false
12StoreOpenButton.visible = true
13 
14-- WORKING PART STOPS HERE --
15 
View all 41 lines...

It didnt work. We tried a local script, removing the local tags in front of the variables, and much more, but it didnt work. How can i get this to work? did i make a mistake in the code? also, the button click wasnt detected at all because the print text wasnt shown in the output.

1 answer

Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
5 years ago

You are putting your functions after the events. Try putting them before. Not only that, only the frame needs to be invisible, thanks to the fact it will make everything invisible with it.

Hope this helped!

0
I dont really get it, in the second script, the non working script, the functions are before the events right? KillPower05 0 — 5y
0
No. These need to be defined before the event happens. Nckripted 580 — 5y
0
Not only that, your other version was much simpler, might want to revert to that one. Nckripted 580 — 5y
Ad

Answer this question