I am making a hunger bar and the script used to work fine, now suddenly it doesn’t run at all. By at all I mean it doesn’t run the loop.
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait() or player.Character
local humanoid = character:WaitForChild("Humanoid")
local background = script.Parent
local bar = background:WaitForChild("Bar")
local maxHunger = 100
local minHunger = 0
local currentHunger = maxHunger
local timePerLoss = 1
local lossPerTime = 5
while wait(timePerLoss) do
print("Looping")
currentHunger -= lossPerTime
bar.Size = UDim2.new(maxHunger / currentHunger, 0, 1, 0)
print("Checking")
if currentHunger <= minHunger then
bar.Size = UDim2.new(minHunger, 0, 1, 0)
humanoid.Health = 0
print("Checked")
player.CharacterAdded:Connect(function()
currentHunger = maxHunger
bar.Size = UDim2.new(1, 0, 1, 0)
print("Reset")
end)
end
end