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

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

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

#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

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)

6 comments

0

Oh shoot! Thanks for the help!

0

Hmm i just tested it fully, no errors, but the audio isnt playing, any ideas?

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?

0

aren't spaced out isn't a problem, it can still work without a new line.

0

true. it doesn't matter if its spaced out or not.

0

its not working cause you didn't set the audioid

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)

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