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

Script that is supposed to make a GUI only visible every 20 seconds doesn't work, why?

So I'm trying to make a script where if a button is clicked, a leaderstat value goes up by one after twenty seconds. However, I only want the GUI the button is attached to to pop up every twenty seconds. The leaderstat value part works fine, but the twenty seconds part doesn't. This is my code:

local debounce = true
script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.Visible = false
	debounce = false
	wait(20)
	debounce = true
	for _,Player in pairs(game.Players:GetPlayers()) do
	    if Player:FindFirstChild("leaderstats") then
	        Player.leaderstats.Videos.Value = Player.leaderstats.Videos.Value +1
	end
	end
	end)

1 comment

0

You only set the gui’s visibility to false in your script, not true.

1 answer

As mattscy rightly said, you forgot to add a line to make the GUI visible again:

local debounce = true
script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Visible = false
    debounce = false
    wait(20)
    debounce = true
   script.Parent.Parent.Visible = true --You forgot to put this in!
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Videos.Value = Player.leaderstats.Videos.Value +1
    end
    end
    end)

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