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

How do I detect if a number value in workspace is equal to a certain number?

Just like the title said, I want to know how I can detect if a number value in workspace is equal to a certain number, im my case its 6, a script with this code: if game.workspace.NumberValue.Value == 6 then end doesnt work please help me this has been bugging me all day

2 answers

The basics:

You want to detect it, use an if statement like you have.

if game.Workspace.NumberValue.Value == 6 then
	--do what you need to do here.
end

However that will only detect it once. If you want to be able to detect when it changes, use a .Changed event, or run it through a wait loop.

If you want it to be a certain number use this

game.Workspace.NumberValue.Changed:Connect(function(changed)
	if changed.Value == 6 then
		--Run a statement
	end
end)

If you want it to be a Smaller number or equal to use this

game.Workspace.NumberValue.Changed:Connect(function(changed)
	if changed.Value >= 6 then
		--Run a statement
	end
end)

if you want it to be a bigger number or equal to use this

game.Workspace.NumberValue.Changed:Connect(function(changed)
	if changed.Value <= 6 then
		--Run a statement
	end
end)

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