I am trying to create a Health GUI but when I test it, nothing happens and developer console says character is a nil value. Please help and thank you. Here is my local script:
local humanoid = game.Players.LocalPlayer.Character.Humanoid humanoid.Changed:Connect(function() local critical = humanoid.MaxHealth/4 if humanoid.Health <= critical then script.Parent.BackgroundColor3 = Color3.new(255,0,0) else script.Parent.BackgroundColor3 = Color3.new(0,255,0) end script.Parent.Size = UDim2.new(0,(humanoid.Health/humanoid.MaxHealth*225),0,40) end)
You need to wait for the character to be created. You can use CharacterAdded event for this purpose.
local plr = game:GetService("Players").LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") humanoid.Changed:Connect(function() local critical = humanoid.MaxHealth/4 if humanoid.Health <= critical then script.Parent.BackgroundColor3 = Color3.new(255,0,0) else script.Parent.BackgroundColor3 = Color3.new(0,255,0) end script.Parent.Size = UDim2.new(0,(humanoid.Health/humanoid.MaxHealth*225),0,40) end)