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

IntValue.Changed not firing, why's that?

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.

1 comment

0

edited my code

2 answers

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

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

2 comments

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'

0

is health a intvalue

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

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