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

Why is it not working when I reset and when I am on client?

It works once, and when you die, it's working on roblox studio but not in roblox player.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local redzone = hum.MaxHealth/3.8
local greenzone = hum.MaxHealth/1.3

hum.Changed:connect(function()
	if hum.Health <= redzone then
		script.Parent.BackgroundColor3 = Color3.new(255, 0 ,0)
		script.Parent.Parent.Parent.ImageLabel.Visible = true
	end
	if hum.Health > redzone then
		local brickcolor =  BrickColor.new("New Yeller")
		local color = brickcolor.Color
		script.Parent.BackgroundColor3 = color
		script.Parent.Parent.Parent.ImageLabel.Visible = false
	end
	if hum.Health > greenzone then
		local brickcolor =  BrickColor.new("Lime green")
		local color = brickcolor.Color
		script.Parent.BackgroundColor3 = color
	end
	script.Parent.Size = UDim2.new(hum.Health / hum.MaxHealth, 0, 0, 20)
	script.Parent.Parent.TextLabel.Text = math.floor(hum.Health)
end)

5 comments

0

hum.HealthChanged instead of hum.Changed?

0

Still not working when I reset, btw it's a health gui.

0

What isn't "working", exactly? I'd like a bit of clarification. Anything coming up in the output?

0

When I reset once, the health gui's changing to 0, but when I reset again, it isn't changing, I think it is because it isn't detecting the character, but when I tried it, it is still the same.

0

Where are you putting the script, is it a localscript, is it somewhere in StarterGui, etc.

1 answer

Just fixed the script, I only removed the player.Character on the variable "char" to fixed it.

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