Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Printing Damage wont work?

Asked by
neoG457 315 Moderation Voter
8 years ago
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

Log in to vote
0
Answered by 8 years ago

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

0
It gets rid of the error but it still doesnt print the damage done. Do you know why? neoG457 315 — 8y
0
Well you have to make the person get damaged... KingLoneCat 2642 — 8y
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... KingLoneCat 2642 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
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
0
It gets rid of the error but it still doesnt print the damage done. Do you know why? neoG457 315 — 8y
0
Add some prints on other lines, and see if the code is stopping before it gets to that line NinjoOnline 1146 — 8y

Answer this question