How can I effectively check if a numbervalue reaches a certain point

I’m basically searching on whether or not the NumberValue “Time” reaches 1 or not and if it does, the script will execute a cloning sequence for a certain model so that it can reset the server’s play space (I’m making a sandbox game).
Thing is, I don’t know how to approach it other than using the “while true do” function, which isn’t always going to work, let alone do I think it is optimized enough to prevent lag if and when it needs to clone bigger models.
Here is my code that I have currently that checks for the value:

while true do
	wait(0.00001)
	game:GetService("ReplicatedStorage"):WaitForChild("SpecialCases")
local reset = game:GetService("ReplicatedStorage").SpecialCases["Server Reset"]:Clone()
if script.Parent.Time == 1 then
	
	reset.Parent = workspace.Base.ItemHolder
	reset.Name = "Scheduled Reset"
	reset.Yeetandelete.Disabled = false
	wait(10)
	reset:Destroy()
	end
	
end

Just in case you want to see the explorer to better understand the situation, here is the screenshot for it and the code:


If anyone could help it would be appreciated

Using a loop to constantly check a value isn’t efficient. Instead, you can use the Changed event, and check if the value exceeds the maximum value.

1 Like

For ValueBase instances, Changed fires only when the value it contains change.

I sort of understand but it seems I’m missing something here
Here’s my code currently after changing it to what you suggested:

   game:GetService("ReplicatedStorage"):WaitForChild("SpecialCases")

local reset = game:GetService("ReplicatedStorage").SpecialCases["Server Reset"]

local object = script.Parent.TimeValue

local function onChanged(timeval)

-- Get the current value of the property

local value = object[timeval]

-- Print a message saying what changed

print(object:GetFullName() .. "." .. timeval .. " (" .. typeof(value) .. ") changed to " .. tostring(value))

end

object.Changed:Connect(onChanged)

edit: nothing gets printed in output however there is no error listed.