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

Value Becomes 0, not going down per second?

The problem is that when "Accessed" is true, the value becomes 0 instantly, and not going down by 1 per second.

local Terminals = workspace.Terminals
local Terminal =  Terminals.Terminal
local Val = Terminal.TerminalValue
local Accessed = Terminal.Accessed

while wait() do
	Accessed.Changed:connect(function(Value)
		if Accessed.Value == true and Val.Value > 0 then
			while Accessed.Value == true and Val.Value > 0 do
				repeat
					Val.Value = Val.Value - 1
					wait(1)
				until 
					Val.Value == 0
				if Val.Value == 0 then
					Accessed.Value = false
				end
			end
		end
	end)
end
	

1 answer

When you are putting the Accessed.Changed function inside the while wait() do loop, it will make a new function for every loop. When the Accessed is changed, it will play all of those cloned functions at once, immediately bringing it down to zero.

You don't actually need to have a loop. You can leave the function as is!

local Terminals = workspace.Terminals
local Terminal =  Terminals.Terminal
local Val = Terminal.TerminalValue
local Accessed = Terminal.Accessed

   Accessed.Changed:connect(function(Value)
        if Accessed.Value == true and Val.Value > 0 then
            while Accessed.Value == true and Val.Value > 0 do
                repeat
                    Val.Value = Val.Value - 1
                    wait(1)
                until 
                    Val.Value == 0
                if Val.Value == 0 then
                    Accessed.Value = false
                end
            end
        end
   end)

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