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:

local entity = script.Parent
local entityHealth = entity:FindFirstChild("health")

entityHealth.Changed:Connect(function(newVal)
    print ('hit')
end)

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

local axe = script.Parent
local blade = axe.Blade

function onBladeTouch (part)
    local entity = part.Parent
    local health = entity:FindFirstChild("health")
    health.Value = health.Value - 5
    print (health.Value)
end


blade.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
local entity = script.Parent
local entityHealth = entity:FindFirstChild("Humanoid").Health

entityHealth.Changed:Connect(function(newVal)
    print ('hit')
end)
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