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

IntValue.Changed not firing, why's that?

Asked by 4 years ago

Hello guys,

I have a model, which also has a part, a script and a intValue called health with value defaulted to 100 as direct child.

The script code is:

1local entity = script.Parent
2local entityHealth = entity:FindFirstChild("health")
3 
4entityHealth.Changed:Connect(function(newVal)
5    print ('hit')
6end)

Then, when my player sword hits this object, I'm decreasing the value of this intValue with the following code:

01local axe = script.Parent
02local blade = axe.Blade
03 
04function onBladeTouch (part)
05    local entity = part.Parent
06    local health = entity:FindFirstChild("health")
07    health.Value = health.Value - 5
08    print (health.Value)
09end
10 
11 
12blade.Touched:Connect(onBladeTouch)

On my sword script I get the console output of the intValue (health) been constantly decreased, but the entityHealth.Changed event from inside my model (code at the top) never gets fired, so I'm wondering whats wrong.

Thanks in advance.

0
edited my code raid6n 2196 — 4y

2 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
1local entity = script.Parent
2local entityHealth = entity:FindFirstChild("Humanoid").Health
3 
4entityHealth.Changed:Connect(function(newVal)
5    print ('hit')
6end)
0
Thanks for the reply. I updated the code and I'm getting the following error: 10:26:08.808 - Workspace.Tree.entity:15: attempt to index number with 'Changed' OliePapis 0 — 4y
0
is health a intvalue raid6n 2196 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Okay, I found the problem / solution

@raid6n my code was right, the problem was that my tool script was type local, so when I changed to script everything worked fine, regardless, thanks again for your reply.

Can you help me to understand why it didn't work when my tool script was local? Thanks

Answer this question