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

How to make something happen when a value has changed?

Here is what I have but it won't work. It has no output:

local a = script.Parent.Parent.Parent.Parent.Health.Health
function shutdown()
	if a.Value >= 25 then
		script.Parent.Sounds.Prepare:Play()
		wait(2)
		script.Parent.Sounds.Siren:Play()
	end
end
a.Changed:connect(shutdown)

2 answers

✓ Accepted answer

I think Changed is a member of objects, not properties. So, if a property of the given object changes, it calls the connected function with the changed property as an argument. So, change the last line accordingly.

a.Changed:connect(shutdown)

1 comment

0

nothing ;(

1.Seriously? No output? When i copied and adapted your script, I got something like this

16:21:06.772 - Workspace.Script:9: attempt to index field 'Value' (a number value)

This happened because Changed event is related to the object, and you indexed it to a property. So, where you have

a.Value.Changed:connect(shutdown)

You should have

a.Changed:connect(shutdown) -- changed fires when one of the properties of the object changes, and you can't point it to a property

6 comments

0

When I change the value of the NumberValue the sounds do not play, nvm I'll have to think of another way to pull it off.

1

you are saying: if health is greater than 25 then alarm everyone :)

0

OHHHHHHH IM SO SORRY :3 IM A NUMPTY

1

on your script

0

Yes I wanted it to do it if it was LOWER than 25 I got it all mixed up, Sorry!

0

lol, now check it again

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