Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Printing Damage wont work?

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.

2 answers

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

3 comments

0

It gets rid of the error but it still doesnt print the damage done. Do you know why?

0

Well you have to make the person get damaged...

0

Also this will only work in the first 4 seconds so how about you put it in the touched function? Like if you make a part that damages you a Touched Function so put it in there every time the person gets hurt it will print the damage...

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.

  • NinjoOnline

2 comments

0

It gets rid of the error but it still doesnt print the damage done. Do you know why?

0

Add some prints on other lines, and see if the code is stopping before it gets to that line

This discussion is preserved as it was. New answers, comments, and votes are closed.