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

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

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)

2 comments

0

I cant tell from just these lines...

0

Cause as I see the problem belongs to these.. Need the leaderboard maybe?

2 answers

✓ Accepted answer
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

3 comments

0

Okay, let me test this out

0

Well, your line 5 got a "parent" supposed to be "Parent" I guess

0

I guess this one could be the answer. Maybe...

I am pretty sure you gotta use

Hum.HealthChanged:connect(function()
	statVal.Health.Value = Hum.Health
end)

1 comment

0

Well, the "HealthChanged" could be usefull. Thanks!

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