wait(4) local Player = game.Players.LocalPlayer local MaxHealth = Player.Character.Humanoid.MaxHealth local CurrentHealth = Player.Character.Humanoid.Health local MaxHealthVal = Instance.new("IntValue", Player.Character) local HealthVal = Instance.new("IntValue", Player.Character) MaxHealthVal.Value = MaxHealth HealthVal.Value = CurrentHealth if HealthVal < MaxHealthVal then DamageDone = MaxHealthVal - HealthVal print(DamageDone) MaxHealthVal = HealthVal end
This script is meant to print the amount of damage whenever it is taken but its given me an error:
Players.xMockery.Backpack.LocalScript:12: attempt to compare two userdata values Script 'Players.xMockery.Backpack.LocalScript', Line 12
Please help.
Ok, so you have a small error in your script the error that pops up in your output is pointing out to you that you can only use logical operators such as addition, subtraction, division, multiplication, less then and greater then with only the "Value" property of the Value you have to make sure you are calling the "Value" property of the Value... something like this.
wait(4) local Player = game.Players.LocalPlayer local MaxHealth = Player.Character.Humanoid.MaxHealth local CurrentHealth = Player.Character.Humanoid.Health local MaxHealthVal = Instance.new("IntValue", Player.Character) local HealthVal = Instance.new("IntValue", Player.Character) MaxHealthVal.Value = MaxHealth HealthVal.Value = CurrentHealth if HealthVal.Value < MaxHealthVal.Value then DamageDone = MaxHealthVal.Value - HealthVal.Value print(DamageDone) MaxHealthVal = HealthVal end
wait(4) local Player = game.Players.LocalPlayer local MaxHealth = Player.Character.Humanoid.MaxHealth local CurrentHealth = Player.Character.Humanoid.Health local MaxHealthVal = Instance.new("IntValue", Player.Character) local HealthVal = Instance.new("IntValue", Player.Character) MaxHealthVal.Value = MaxHealth HealthVal.Value = CurrentHealth if HealthVal.Value < MaxHealthVal.Value then DamageDone = MaxHealthVal.Value - HealthVal.Value print(DamageDone) MaxHealthVal.Value = HealthVal.Value end
The problem you had is you forgot to add .Value to the HealthVal and MaxHealthVal, as they are both IntValue's and you set their values already, but you never checked that their values.
Hope this helped and please accept answer and +1 the answer.