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)
How high is your Defence Value?
Try having the local value outside of the functions scope. That might be your problem.
try this, im not sure if it will work
script.Parent.Touched:Connect(function(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)