Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
H34E7R 19
5 years ago

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.

Ad
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
5 years ago
Edited 5 years ago

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)

Answer this question