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

How to acsess a local palyers humanoid to display his health in a gui?

Asked by
hokyboy 270 Moderation Voter
4 years ago

So i couldent find a tutorial on this I want to make a gui that says health:100 but i have no idea how to acces a local players humanoid

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Here's how to access the players humanoid's health:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

function onHealthChanged(newHealth)
    --Do whatever you want with the newHealth here
end

player.CharacterAdded:Connect(function(char)
    local character = char
    local humanoid = char:WaitForChild("Humanoid")
    healthChanged:Disconnect()
    healthChanged = humanoid.HealthChanged:Connect(onHealthChanged)
end)

local healthChanged = humanoid.HealthChanged:Connect(onHealthChanged)
Ad

Answer this question