salutations all, i come with an issue
i’m trying to use a numbervalue inside of the character as a replacement of the Humanoid’s health,
eg - the health of the player decreases by 10
numbervalue decreases by 10
^^ but it should not mirror the humanoid’s health
this is so later i can make the humanoid’s health return to 100
the issue is, the numbervalue does not do this and just halts/stays at the default value set for it, anyyy help?!
here is my code (startercharacterscripts):
local function onDamageTaken(damage)
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local healthNumberValue = character:FindFirstChild("Health")
if humanoid and healthNumberValue then
local currentValue = healthNumberValue.Value
if humanoid.Health > damage then
humanoid.Health = humanoid.Health - damage
healthNumberValue.Value = currentValue - damage
else
healthNumberValue.Value = currentValue - humanoid.Health
humanoid.Health = 0
end
end
end
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
local healthNumberValue = game.Players.LocalPlayer.Character:FindFirstChild("Health")
if healthNumberValue then
healthNumberValue:Destroy()
end
end)
game.Players.LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
onDamageTaken(game.Players.LocalPlayer.Character.Humanoid.MaxHealth - game.Players.LocalPlayer.Character.Humanoid.Health)
end)
i’m still a beginner so all help is appreciated, thank you!
Health is my NumberValue