The Hunger System Not Working

Hello, Am Begginer Scripter Making Hunger System Based Youtube Tutorial, And It Worked Before But Somehow It Not Work Anymore. Hunger Bar Itself Decrease, But Problem Is When Hunger Bar Reached 0, Player Not Dies, And There Is No Error In Outputs, Any Help?

Local Script In Hunger Bar Gui

local Player = game.Players.LocalPlayer
local Hunger = Player:WaitForChild("Hunger")

local GUI = script.Parent
local BarExterior = GUI.Bar
local BarInterior = BarExterior.Bar

local function UpdateHunger()

	
	local CurrentValue = Hunger.Value
	local Formula = math.clamp(CurrentValue/100, 0, 1)
	
	BarInterior:TweenSize(UDim2.new(Formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.15, true)
	
end

UpdateHunger()
Hunger.Changed:Connect(function()
	UpdateHunger()
end)

Script In ServerScriptService

local DECREASE_FREQUENCY = 100
local DECREASE_AMOUNT = 6

game.Players.PlayerAdded:Connect(function(Player)
	
	
	local Hunger = Instance.new("IntValue", Player)
	Hunger.Name = "Hunger"
	Hunger.Value = 100
	
	Player.CharacterAdded:Connect(function()
		Hunger.Value = 100
	end)
	
while wait(DECREASE_FREQUENCY) do	
if Hunger.Value <= 0 then
    Player.Character:BreakJoints()
    else
    Hunger.Value -= DECREASE_AMOUNT
    end
  end
end)

You could try changing the Player.Character:BreakJoints() line to these lines:

local char = Player.CharacterAdded:Wait()
char.Humanoid.Health = 0

I’m not sure why BreakJoints() is not working, but I usually use this to kill the player.

Still Not Work, I Just Realized That It Dies After Some Second, I Still Don’t Know Why.

It looks like it’s only checking if the hunger value is 0 every 100 seconds, because it’s waiting for the decrease frequency (100 seconds), until it run’s the loop again.

Try changing it to 1 or try adding a print statement to see when it prints.

Are there any errors in the output if so show us. If there are no errors then put print statements throughout the script to see what is running and what’s not running.

Sorry For Late Response, So Like This?

local DECREASE_FREQUENCY = 1
local DECREASE_AMOUNT = 6

game.Players.PlayerAdded:Connect(function(Player)
	
	
	local Hunger = Instance.new("IntValue", Player)
	Hunger.Name = "Hunger"
	Hunger.Value = 100
	
	Player.CharacterAdded:Connect(function()
		Hunger.Value = 100
	end)
	
while wait(DECREASE_FREQUENCY) do	
if Hunger.Value <= 0 then
	Player.Character:BreakJoints()
	print("death")
	else
	print("decrease")	
    Hunger.Value -= DECREASE_AMOUNT
    end
  end
end)

Yes, check if the output prints “death” once health gets to 0. If it does and the player still does not die, refer to my previous post and change the :BreakJoints to

local char = Player.CharacterAdded:Wait()
char.Humanoid.Health = 0

Let me know if this works.

print work good and realized that even reached 0, until decrease again, player wont dies.

Try removing the else and decreasing it before checking if it’s 0.

1 Like

You Guys Having 8000 IQ, Thanks!

Ah yeah he had the right idea, I did not look close enough. Also, if he solved your problem, please mark it as a solution. This is so other people that come here with similar problems can easily find a easy solution. Thanks!

1 Like

You Helped Me Lot Too!, Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.