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

How do you get a script to perform an action once a value reaches a certain number?

Asked by 2 years ago
Edited 2 years ago

This is the script i have made. "then" and "end" are red underlined and it wont work. ~~~~~~~~~~~~~~~~~

script.Parent.Num.Value = 4 then script.Parent.Sound:Play() end

~~~~~~~~~~~~~~~~~

3 answers

Log in to vote
1
Answered by 2 years ago

try

script.Parent.Num.Value.Changed:Connect(function(t)
    if t == 4 then 
        script.Parent.Sound:Play() 
    end
end)

or

script.Parent.Num:GetPropertyChangedSignal("Value"):Connect(function()
    if script.Parent.Num.Value == 4 then
        script.Parent.Sound:Play() 
    end
end)

if you still have errors, or you want to ask other things, simply dm me on discord

Blue Duck#8344

Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Multiple issues with your code;

  1. No if statement.
  2. They aren't spaced out.
  3. There aren't 2 "=" signs.

Here is the fixed version:

if script.Parent.Num.Value == 4 then
    script.Parent.Sound:Play()
end)
0
Oh shoot! Thanks for the help! Student20986 0 — 2y
0
Hmm i just tested it fully, no errors, but the audio isnt playing, any ideas? Student20986 0 — 2y
0
Can you give me an idea of the structure? Like does the script take place in a model with Value inside of in and the audio inside of it? KneeDeepInTheDoot 13 — 2y
0
aren't spaced out isn't a problem, it can still work without a new line. WINDOWS10XPRO 438 — 2y
View all comments (2 more)
0
true. it doesn't matter if its spaced out or not. JesseSong 3916 — 2y
0
its not working cause you didn't set the audioid JesseSong 3916 — 2y
Log in to vote
0
Answered by 2 years ago

You'll need to check if it changes, then check if the change is 4.

script.Parent.Num.Value.Changed:Connect(function(newval)
    if newval== 4 then 
        script.Parent.Sound:Play() 
    end
end)

Answer this question