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

Why my script doesn't detect the player's health?

Asked by 8 years ago

So, I think the problem is the variable in the script I guess? Cause when I see the output its the problem maybe? So here's my script:

Hum = script.Parent.Humanoid
statVal = game.Players.LocalPlayer.Stats --Stats is the leaderboard stuff But no need to change it
Hum.Health.Changed:connect(function()
    statVal.Health.Value = Hum.Health
end)

Output : 17:09:19.219 - Workspace.Player1.HealthDetect:3: attempt to index field 'Health' (a number value) Note : Script is inside StarterCharacterScript. Please answer in the answer bar, not comments.

EDIT For FlaminSparrow : Another problem when I type this code :

Hum = script.Parent.Humanoid
statVal = game.Players.LocalPlayer.Stats
Hum.HealthChanged:connect(function()
   statVal.Health.Value = Hum.Health
end)

Output : 17:32:03.756 - Players.Player1.PlayerGui.ScreenGui.TabFrame.StatFrame.Health.LocalScript:4: attempt to concatenate global 'HealthPercentage' (a userdata value)

0
I cant tell from just these lines... FlaminSparrow 65 — 8y
0
Cause as I see the problem belongs to these.. Need the leaderboard maybe? krisxxxz 45 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
Hum = script.Parent.Humanoid
statVal = game.Players.LocalPlayer.Stats
statHealth = statVal:WaitForChild('Health')
Hum.HealthChanged:connect(function()
   statHealth.Value = script.parent.Humanoid.Health -- I have had similar problems to this and this is what i did to fix it
end)

I do not know if this will work

0
Okay, let me test this out krisxxxz 45 — 8y
0
Well, your line 5 got a "parent" supposed to be "Parent" I guess krisxxxz 45 — 8y
0
I guess this one could be the answer. Maybe... krisxxxz 45 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

I am pretty sure you gotta use

Hum.HealthChanged:connect(function()
    statVal.Health.Value = Hum.Health
end)
0
Well, the "HealthChanged" could be usefull. Thanks! krisxxxz 45 — 8y

Answer this question