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)
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.
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
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!