I have a simple damage script that deals damage to the player on touch, per usual. I have a variable for defense that is pulled from a NumberValue object that the player's character model gets when the player joins the server or respawns. However the defense variable within the script never updates. Any help?
function onTouched(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if (human ~= nil) then
local Defense = hit.Parent.CharDefense
local Damage = 1 - (Defense.Value / 100)
print(Damage)
human.Health = human.Health - Damage
end
end
script.Parent.Touched:connect(onTouched)

2 comments
it works fine for me, check if you didnt misspell something or if you get any errors when you test it
I don't get any errors and the script does work. To be more specific, when the NumberValue for defense is updated in the player model, the value is not updated within the script. So every time damage is taken it is using the defense value the player had when the player joined the game, and never updating.