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

How to make something happen when a value has changed?

Asked by
Nidoxs 190
9 years ago

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

Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

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)
0
nothing ;( Nidoxs 190 — 9y
Ad
Log in to vote
1
Answered by
davness 376 Moderation Voter
9 years ago

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
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. Nidoxs 190 — 9y
1
you are saying: if health is greater than 25 then alarm everyone :) davness 376 — 9y
0
OHHHHHHH IM SO SORRY :3 IM A NUMPTY Nidoxs 190 — 9y
1
on your script davness 376 — 9y
View all comments (2 more)
0
Yes I wanted it to do it if it was LOWER than 25 I got it all mixed up, Sorry! Nidoxs 190 — 9y
0
lol, now check it again davness 376 — 9y

Answer this question