On/Off Buttons for a Timer

  1. I am trying to make a Start Job button and an End Job button, but I can’t seem the get the code working.

  2. The Issue is that I can get it to start counting but the End Job button doesn’t end the counting.

START JOB SCRIPT v

local repFirst = game:GetService("ReplicatedFirst")
local button = script.Parent
local boolValue = repFirst.MoneyGenBool.Value
local counterValue = script.Parent.Parent.CounterValue

counterValue:GetPropertyChangedSignal("Value"):Connect(function()
    button.Text = tostring(counterValue.Value)
end)

button.MouseButton1Click:Connect(function()
    while boolValue == true do
        counterValue.Value = counterValue.Value + 1
        task.wait(1)
    end
end)

STOP JOB SCRIPT v

local button = script.Parent
local repFirst = game:GetService("ReplicatedFirst")
local bool = repFirst.MoneyGenBool

button.MouseButton1Click:Connect(function()
		if bool then
		bool.Value = false
	end
end)

What my START JOB SCRIPT is doing is it starts counting while a boolValue is set to true, and my STOP JOB SCRIPT sets the boolValue to false when clicked.

I found the boolValue can only be changed via script inside ReplicatedFirst so that’s where I put it.

You are referencing the variable which holds the value and not the current value. “boolvalue” variable will always be false because it contains the value of the boolvalue instance at that instant. So even if you change the bool value it doesn’t change anything as long as you’re referencing the variable. To fix the issue, simply reference the boolvalue var with repFirst.MoneyGenBool
In the while loop,

while boolValue.Value do --[[Bla bla bla]] end
1 Like