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.
local entity = script.Parent local entityHealth = entity:FindFirstChild("Humanoid").Health entityHealth.Changed:Connect(function(newVal) print ('hit') end)
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