I don't know whats happening, I made multiple local scripts, all in areas that connect to the client (starter pack, starter gui, starter player scripts), each script works perfectly fine in studio, but they don't seem to work in game. Below is one of those scripts. Why doesn't this work?
line 1 currently returns an error - infinite yield possible on "LocalPlayer"
local char = game.Players:WaitForChild("LocalPlayer")
local hum = char:WaitForChild("Character").Humanoid
local bar = script.Parent.HealthBar
local border = script.Parent
local lowHealth = hum.MaxHealth/4
local fullHealth = hum.MaxHealth
local healthtxt = script.Parent.Parent.HealthPercentage
hum.Changed:Connect(function()
local HP = hum.Health / hum.MaxHealth
local roundedHP = math.floor(hum.Health + 0.5)
healthtxt.Text = roundedHP .."%"
if roundedHP <= lowHealth then
healthtxt.TextColor3 = Color3.fromRGB(211,0,0)
elseif roundedHP == 100 then
healthtxt.TextColor3 = Color3.fromRGB(0,255,0)
else
healthtxt.TextColor3 = Color3.fromRGB(255,255,255)
end
if hum.Health > lowHealth then
bar.BackgroundColor3 = Color3.fromRGB(255,255,255)
border.BackgroundColor3 = Color3.fromRGB(33,33,33)
else
bar.BackgroundColor3 = Color3.fromRGB(211,0,0)
border.BackgroundColor3 = Color3.fromRGB(89,29,29)
end
bar.Size = UDim2.new(HP,0,1,0)
end)

3 comments
just use game.Players.LocalPlayer instead of waiting
yeah i did that before, but thats when i first got the error. I switched to this to see if that fixed the problem
Actually WaitForChild("LocalPlayer") would wait for an object called LocalPlayer