i have a script for a hunger bar, and sprint. but for some reason the hunger bar does not go down
local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local NormalWalkSpeed = 40
local NewWalkSpeed = 70
local sprinting = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character
UIS.InputBegan:connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
character.Humanoid.WalkSpeed = NewWalkSpeed
sprinting = true
end
end)
UIS.InputEnded:connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
character.Humanoid.WalkSpeed = NormalWalkSpeed
sprinting = false
end
end)
local hungval = script.Parent.HGMBackground.Hunger
local bar = script.Parent.HGMBackground.Bar
if sprinting == true then
while true do
hungval.Value = hungval.Value - 1 -- i think this is the issue because my hunger bar goes down with the hungval value.
wait(1)
if hungval.Value == 0 then
hungval.Value = 0
character.Humanoid.Health = character.Humanoid.Health - 1
end
end
else
while true do
hungval.Value = hungval.Value - 1
wait(5)
if hungval.Value == 0 then
hungval.Value = 0
character.Humanoid.Health = character.Humanoid.Health - 1
end
end
end
while true do
bar.Size = UDim2.new(hungval.Value / 100, 0, 1, 0)
end