New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

# I keep pressing the close gui button but it doesnt work whats wrong with my script?

Asked by 3 months ago
Edited 3 months ago

this is my script

local window = game.ReplicatedStorage.StatsGUI.StatsWindow.Visible

function onClicked(GUI)
window = false
script.Parent.MouseButton1Click:Connect(onClicked)
end


### 2 answers

Log in to vote
0
Answered by
BashGuy10 327
3 months ago

Hi there, im BashGuy10. I have a simple script that you can adjust to your needs!

You should use :Connect(function(). As this makes it much cleaner.

local window = script.Parent.Parent.Frame -- Change this to your location

script.Parent.MouseButton1Click:Connect(function()
if window.Visible == true then
window.Visible = false
end
end)


Hope this helps!

0
It did thanks AlphaFlame5 -3 — 3mo
Log in to vote
0
Answered by 3 months ago

I think it because you connected the function inside the function itself, this way, the function will never activate

you should connect the function outside the function instead:

local window = game.ReplicatedStorage.StatsGUI.StatsWindow.Visible

function onClicked(GUI)
window = false
end
script.Parent.MouseButton1Click:Connect(onClicked)



`

0
I guess my function is wrong then AlphaFlame5 -3 — 3mo
0
because its still not working AlphaFlame5 -3 — 3mo
0
Ohhh I see why, its because you set local window = statswindow.visible which just sets window to false, In order to be able to do this, you need to set window as StatsWindow and inside the function do window.Visible = false Ido_nothaveUsername 208 — 3mo