I want to make this function run only once and then never again:
button.MouseButton1Click:Connect(function()
InfoLabel.Text = "You Generated a New Color "..clicks + 1 .." Time(s)! Keep Going."
PreviewLoopKeeper = false
The issue is, even after the while loop it’s in breaks, it still runs.
I’ve tried solutions like disconnecting it, but it didn’t work. Maybe I did it wrong.
Here is the whole while loop:
-- Preview
while PreviewLoopKeeper do
RGB_RNG.RGBrandomizer(InfoLabel)
RGB_RNG.RGBrandomizer(frame)
button.MouseButton1Click:Connect(function()
InfoLabel.Text = "You Generated a New Color "..clicks + 1 .." Time(s)! Keep Going."
PreviewLoopKeeper = false
end)
task.wait(1)
end
Whole script:
-- Variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RGB_RNG = require(ReplicatedStorage.MODULES.RGBrandomizer)
local button = script.Parent.Parent.ChangeColor
local InfoLabel = script.Parent.Parent.TextLabels.InfoLabel
local clicks = 0
local frame = script.Parent.Parent.ColorChangingFrame
local PreviewLoopKeeper = true
local debounce = false
----------------------------------------------------------------------------------------------------
-- Preview
while PreviewLoopKeeper do
RGB_RNG.RGBrandomizer(InfoLabel)
RGB_RNG.RGBrandomizer(frame)
button.MouseButton1Click:Connect(function()
InfoLabel.Text = "You Generated a New Color "..clicks + 1 .." Time(s)! Keep Going."
PreviewLoopKeeper = false
end)
task.wait(1)
end
----------------------------------------------------------------------------------------------------
-- Color Generated Amount Counter
button.MouseButton1Click:Connect(function()
PreviewLoopKeeper = false
if not debounce then
debounce = true
clicks += 1
RGB_RNG.RGBrandomizer(InfoLabel)
InfoLabel.Text = "You Generated a New Color "..clicks + 1 .." Time(s)! Keep Going."
InfoLabel.TextSize = 18
task.wait(.5)
debounce = false
end
end)
----------------------------------------------------------------------------------------------------