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

How do i wait for a int value to have a certain value?

I have a script here:

Counter = Instance.new("IntValue", workspace)
Counter.Name = "PlayerCount"
Counter.Value = #game.Teams.Eliminating:GetPlayers()

while true do
	wait(20)
	if Counter.Value < 1 or Counter.Value == 1 then
		print("There is a winner")
		game.Workspace.Ground:Destroy()
		print("Ground has melted")
		wait(3)
		for _, player in ipairs(game.Players:GetPlayers()) do
    player.Team = game.Teams.Eliminating
		print("Teams have changed")
		game.Lighting.Ground:Clone().Parent = game.Workspace
		print("Snow has refrosen")
		end
	end
end

But the problem with this is that it is not efficiant, so how do I change this script so that instead of doing a loop, it simply waits for the counter value to have a value = or lower than 1.

Thanks in advance.

1 answer

✓ Accepted answer

There is an event of every Value object called Changed which fires each time the Value property of that Value object is changed. Using this, each time the value is changed we can check what the value was changed to and do stuff at certain values.

Example:

local intValue = Instance.new("IntValue")
intValue.Parent = game.Workspace

intValue.Changed:connect(function(value)
	if value == 3 or value == 5 then
		print("The value was set to "..tostring(value).."!")
	end
end)

intValue.Value = 2
intValue.Value = 3 -- Output: The value was set to 3!
intValue.Value = 4
intValue.Value = 5 -- Output: The value was set to 5!

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