Hello! i need help, i don’t know how to get the player HP and i need some help with that… could someone help me please!
local Hum = v.Character:FindFirstChild("Humanoid")
if Hum and Hum.Health > 0 then --Checks if player is alive.
Hum.Health = Hum.Health - 15 --Change "100" to the damage the player should take.
wait(1)
end
Do you mean you want to have a text that shows their HP?
wait(3)
local textlabel = --define textlabel here
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Health.Changed:Connect(function()
textlabel.Text = "Health: "..humanoid.Health
end)
If you mean to use a frame as a custom health bar, you just set the size of the frame proportionately to the health
so parent this under a frame, and it will resize the frame based on the current health and the max health
(make sure that the anchorpoint of the frame is (0,0.5) before you put it where you want it on the screen
local sp = script.Parent
local OriginalSizeX = sp.Size.X.Scale
local OriginalSizeY = sp.Size.Y.Scale
game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
game.Players.LocalPlayer.Character.Humanoid.HealthChanged:Connect(function(Health)
local MaxHealth = Humanoid.MaxHealth
if Health >0 then
local SizeOutputX = (OriginalSizeX*Health)/ MaxHealth
sp.Size = UDim2.new(SizeOutputX, 0, OriginalSizeY, 0)
end
end)
If you wanna do a text that show players health, i already did this in a script a week ago
[ Put this script in a local script inside of a TextLabel ] :
–>variables
local humanoid = game.Players.LocalPlayer.Character:WaitForChild(‘Humanoid’)