local DotHunger = HungerFrame.DotHunger
local Circle = HungerFrame:WaitForChild("Circle")
local HungerShow = HungerFrame.HungerShow
local MaxHunger = 100
local HungerValue = Player:WaitForChild("HungerValue")
local HungerColor
local HungerChange
HungerValue:GetPropertyChangedSignal("Value"):Connect(function()
HungerColor = Color3.fromRGB(218, 133, 65):Lerp(Color3.fromRGB(13, 105, 172), HungerValue.Value/MaxHunger)
HungerChange = HungerValue.Value/MaxHunger
DotHunger:TweenSize(UDim2.new(HungerChange, 0, 1, 0), "In", "Quad", 1)
DotHunger.BackgroundColor3 = HungerColor
HungerShow.Text = HungerValue.Value.."/"..MaxHunger
Circle.ImageColor3 = HungerColor
end)
while wait(3) do
if HungerValue.Value >= 1 then
HungerValue.Value = HungerValue.Value - 1
end
if HungerValue.Value == 0 then
repeat wait(1)
Humanoid.Health = Humanoid.Health - 5
until Humanoid.Health == 0 or HungerValue.Value < 0
end
end
Player.CharacterAdded:Connect(function()
HungerValue.Value = MaxHunger
end)
Oops I messed up, it should be something like this:
local MaxHunger = 100
local HungerValue
game.Players.PlayerAdded:Connect(function(player)
local HungerVal = Instance.new("IntValue", player)
HungerVal.Name = "HungerValue"
HungerVal.Value = 0 -- Starting at 0
player.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function() -- When Humanoid Dies
print(player.Name.."Died")
player.CharacterAdded:Wait() -- When player spawns again
HungerVal.Value = MaxHunger -- Value is set to 100
print("Hunger Max")
end)
end)
end)
Why set HungerValue? If you’re defining it outside of the characteradded event it’d get changed every time the player joins. Essentially, only the player that joined most recently would have their hunger updated.
Yes that is my apologies. It’s not necessary to set the HungerValue as it’s already defined.
I also forgot that “characterAdded” function should be moved outside of the Instance, as it will keep duplicating every time the character is added. Thus it will only happen for the most recent player as well.