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

My custom health bar script isn't working, Why? [solved]

It's supposed to make my custom health bar change the color from red to green, and change the size, but it doesn't do anything, why?

function barFunction(plr) -- supposed to make me custom health bar work
	local gui = plr.PlayerGui:WaitForChild("Health", 99)
	local hbar = gui:WaitForChild("Bar", 99)
	local playerhp = gui:WaitForChild("PlayerHealth", 99)
	local maxhealth = gui:WaitForChild("MaxHealth", 99)
	local percent = playerhp.Value / maxhealth.Value
	playerhp.Changed:connect(function()
		--//color
		local green = percent
		local red = 1 - green
		hbar.BackgroundColor3 = Color3.new(red,green,0)
		--//size
		hbar.Size = UDim2.new(0,percent * x,0,y)
	end)
end


game.Players.PlayerAdded:Connect(function(plr)
	barFunction(plr) -- launches it
end)

2 comments

0

you cant use the playeradded event inside a local script

0

Edit: Marked as solved

1 answer

Nevermind, Solved I can do a loop.

3 comments

0

theres a much better way of using a loop like using the HealthChanged event on the humanoid

1

Didn't need to write an answer. Could've commented or edited the question

0

^ yup

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