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

Can't get humanoid in a local script to show my health in gui, (?)

That's my script :

local Players = game:GetService("Players").LocalPlayer local Character = Players:FindFirstChild("Character") local Humanoid = Character:FindFirstChild("Humanoid")

function Health() script.Parent.Text = tostring(Humanoid.Health.."Health") end Health() Humanoid.Health.Changed:Connect(Health)

That's basically my script somewhy it doesn't work, Thanks for helping

1 comment

0

It will be helpful if you keep the script in Lua block code

1 answer

✓ Accepted answer

Well, there were few flaws in your code. I edited all of them and it might work. Comments are also added what's wrong.

local Players = game:GetService("Players").LocalPlayer 
-- local Character = Players:FindFirstChild("Character") Well, don't just find Character of the player, the Character takes some time to load
repeat wait() until Players.Character -- Waits for the Character to load completely
local Humanoid = Players.Character:FindFirstChild("Humanoid")

function Health() 
	script.Parent.Text = tostring(Humanoid.Health.." Health") 
end 

Health() 

-- Humanoid.Health.Changed:Connect(Health) Don't use Health.Changed, roblox have in-built function to detect the Change in Health, it is called 'HealthChanged'
Humanoid.HealthChanged:Connect(Health)

Lemme know if it helps!

2 comments

1

Thx

0

It will be helpful if you mark it as the answer

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