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

Health bar resets on spawn but wrong way?

--LOCAL--
local p = script.Parent.Parent.Parent.Parent.Parent.Name
local Camera = game.Workspace.CurrentCamera

--MAIN--
script.Parent.MouseButton1Click:Connect(function()
	Camera.CameraType="Custom"
	game.Players[p].TeamColor = BrickColor.new("Really black")
	game.Workspace[p].Humanoid.Health = 0
	script.Parent.Parent.Parent.Enabled = false
	script.Parent.Parent.Parent.Parent.health.white.Visible=true
	script.Parent.Parent.Parent.Parent.health.white.red.Visible=true
	script.Parent.Parent.Parent.Parent.health.white.red.green.Visible=true
	
end)

When I die this script will not work since it only works on the main menu. So when I die the health bar will disappear. I try to make ResetOnSpawn false but it will keep the health bar red condition after I die. Any one know how to do it?

1 answer

I have some code for the health bar right here:

local HealthMax = 100
local Frame = script.Parent.Frame.Frame
local player = game.Players.LocalPlayer.Character

player:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
        Frame.Size = UDim2.new(player.Humanoid.Health/player.Humanoid.MaxHealth, 0, 1, 0) -- This division will aways give a number between 0 and 1, so we know the percent of players health
end)

This will scale the frame based on the current health and max-health. It divides them and gives a number that is below 1, so it can tell the percentage. Hope this helps, good luck!

2 comments

0

there is an Humanoid.HealthChanged event especifically using Change event in Health - https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

0

Right.

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