-- Custom Thirst and Hunger System Script -- Configuration local startingThirst =…
- User
-- Custom Thirst and Hunger System Script
-- Configuration local startingThirst = math.pi -- Starting thirst value for players local startingHunger = math.pi -- Starting hunger value for players local thirstDecreaseInterval = 5 -- Time (in seconds) between thirst decreases local hungerDecreaseInterval = 7 -- Time (in seconds) between hunger decreases local thirstDecreaseAmount = 1 -- Amount to decrease thirst each interval local hungerDecreaseAmount = 1 -- Amount to decrease hunger each interval local healthDecreaseAmount = 5 -- Amount of health to decrease when thirst or hunger is depleted local healthDecreaseInterval = 2 -- Time (in seconds) between health decreases when depleted
-- Function to set up thirst and hunger stats for the player local function setupStats(player) -- Create a leaderstats folder to hold the stats (optional, for display) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
code-- Create Thirst stat local thirst = Instance.new("IntValue") thirst.Name = "Thirst" thirst.Value = startingThirst thirst.Parent = leaderstats -- Create Hunger stat local hunger = Instance.new("IntValue") hunger.Name = "Hunger" hunger.Value = startingHunger hunger.Parent = leaderstats -- Coroutine to decrease thirst over time coroutine.wrap(function() while player.Parent do wait(thirstDecreaseInterval) if thirst.Value > 0 then thirst.Value = math.max(thirst.Value - thirstDecreaseAmount, 0) end end end)() -- Coroutine to decrease hunger over time coroutine.wrap(function() while player.Parent do wait(hungerDecreaseInterval) if hunger.Value > 0 then hunger.Value = math.max(hunger.Value - hungerDecreaseAmount, 0) end end end)() -- Coroutine to decrease health if thirst or hunger is depleted coroutine.wrap(function() while player.Parent do -- Check every few seconds wait(healthDecreaseInterval) local character = player.Character if character and character:FindFirstChild("Humanoid") then local humanoid = character.Humanoid if thirst.Value <= 0 or hunger.Value <= 0 then humanoid.Health = math.max(humanoid.Health - healthDecreaseAmount, 0) end end end end)() - Assistant
- User
local player = game.Players.LocalPlayer
-- Function to handle the character local function onCharacterAdded(character) local humanoid = character:WaitForChild("Humanoid")
- Assistant