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 4 years ago

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

script.Parent.OpenedStoreFrame.BackgroundTransparency = 1
function leftClickopenStore()
    if script.Parent.OpenedStoreFrame.BackgroundTransparency == 1 then
        print("BGTransparency to 0")
        script.Parent.OpenedStoreFrame.BackgroundTransparency = 0
    elseif script.Parent.OpenedStoreFrame.BackgroundTransparency == 0 then
        script.Parent.OpenedStoreFrame.BackgroundTransparency = 1
        print ("BGTransparency to 1")
    end
end


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

-- Defines GUI objects of store --
local OpenedStoreFrame = script.Parent.OpenedStoreFrame
local StoreText = script.Parent.OpenedStoreFrame.TextLabel
local CloseButton = script.Parent.OpenedStoreFrame.CloseButton
local VipGamepassIcon = script.Parent.OpenedStoreFrame.VipGamepass
local StoreOpenButton = script.Parent.StoreFrame.StoreButton
-- Makes store gui objects invisible at start of game --
OpenedStoreFrame.Visible = false
StoreText.Visible = false
CloseButton.Visible = false
VipGamepassIcon.visible = false
StoreOpenButton.visible = true

-- WORKING PART STOPS HERE --

-- Defines store button click functions --
script.Parent.StoreFrame.StoreOpenButton.MouseButton1Click:Connect(OpenStoreClicked)
script.Parent.OpenedStoreFrame.CloseButton.MouseButton1Click:Connect(CloseStoreClicked)
-- Defines store button function and detects click --
function OpenStoreClicked()
    if OpenedStoreFrame.Visible == false then
        OpenedStoreFrame.Visible = true
        StoreText.Visible = true
        VipGamepassIcon.Visible = true
        CloseButton.Visible = true
        StoreOpenButton.Visible = false
        print("StoreGUIVisible")
    end
end

-- Defines store closing button function and detects click --
function CloseStoreClicked()
    if CloseButton.Visible == true then
        OpenedStoreFrame.Visible = false
        StoreText.Visible = false
        VipGamepassIcon.Visible = false
        CloseButton.Visible = false
        StoreOpenButton.Visible = true
        print("StoreGUIHidden")
    end
end

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
4 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 — 4y
0
No. These need to be defined before the event happens. Nckripted 580 — 4y
0
Not only that, your other version was much simpler, might want to revert to that one. Nckripted 580 — 4y
Ad

Answer this question