I'm trying to make a script that makes a player slow down when damaged. So, if my max health is 100 and my health is 50 and my speed is 16, my walkspeed should become 8. This is the code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
repeat wait() until character.Humanoid
local humanoid = character.Humanoid
local originalSpeed = humanoid.WalkSpeed
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
print("health changed")
humanoid.WalkSpeed = humanoid.Health / humanoid.MaxHealth * originalSpeed
print("walkspeed updated:", humanoid.WalkSpeed)
end)
end)
end)
It works perfectly fine, until this happens:
health changed walkspeed updated: 8 health changed walkspeed updated: 8.1613359451294 health changed walkspeed updated: 8.3214712142944 health changed walkspeed updated: 8.4838285446167 health changed walkspeed updated: 8.6445035934448
why does this happen, and how can i fix it?

1 comment
What is the origional speed?