Well, I did this script about a month or two ago, and I didn’t have that much knowledge of scripts (I’m still not good at this, but I’m improving). The script tries to lower some values of numberValue to 0 (thirst and hunger), when it is at 0, life goes down by -2, hunger can be removed but that is another process. At the moment, I don’t think the script is efficient, so I come to ask for your help (If you see something from the ProfileService, it is because I am going to change it to that after this)
local ProfileService = require(game.ServerScriptService:WaitForChild("DataStore"):WaitForChild("Configurations"):WaitForChild("DataManager"))
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local char = script:FindFirstAncestorWhichIsA("Model")
local player = Players:GetPlayerFromCharacter(char)
local Profile = ProfileService:Get(player, true)
local Hunger = player:WaitForChild("Player data"):WaitForChild("NeedsPlayerStats"):WaitForChild("Hunger")
local Thirst = player:WaitForChild("Player data"):WaitForChild("NeedsPlayerStats"):WaitForChild("Thirst")
local SprintHunger = ReplicatedStorage:WaitForChild("SprintHunger")
SprintHunger.OnServerEvent:Connect(function(plr)
local Character = workspace:FindFirstChild(plr.Name)
if Character:WaitForChild("Hunger/Thirst").Run.Value == false then
Character:WaitForChild("Hunger/Thirst").Run.Value = true
else
Character:WaitForChild("Hunger/Thirst").Run.Value = false
end
end)
local function HungryAndThirstZero()
wait()
if Thirst.Value <= 0 or Hunger.Value <= 0 then
while Thirst.Value <= 0 or Hunger.Value <= 0 do
script.Parent.Humanoid.Health = script.Parent.Humanoid.Health - 2
wait(5)
end
end
end
repeat
local WaitRandom = math.random(28, 35)
local WaitRandomRun = math.random(23, 25)
local WaitHunger = math.random(4, 7)
if script.Run.Value == false then
wait(WaitRandom)
else
wait(WaitRandomRun)
end
if Thirst.Value <= 0 then
HungryAndThirstZero()
else
if script.Run.Value == false then
if script.Parent.Sistemas.Taken.Value == false then
Thirst.Value -= 1
elseif script.Parent.Sistemas.Taken.Value == true then
if script.Parent.Sistemas.TakenSelect.Value == "Lumber" then
Thirst.Value -= 2
end
end
elseif script.Run.Value == true then
if script.Parent.Sistemas.Taken.Value == false then
Thirst.Value -= 2
elseif script.Parent.Sistemas.Taken.Value == true then
if script.Parent.Sistemas.TakenSelect.Value == "Lumber" then
Thirst.Value -= 3
end
end
end
end
wait(WaitHunger)
if Hunger.Value <= 0 then
HungryAndThirstZero()
else
if script.Run.Value == false then
if script.Parent.Sistemas.Taken.Value == false then
Hunger.Value -= 1
elseif script.Parent.Sistemas.Taken.Value == true then
if script.Parent.Sistemas.TakenSelect.Value == "Lumber" then
Hunger.Value -= 2
end
end
elseif script.Run.Value == true then
if script.Parent.Sistemas.Taken.Value == false then
Hunger.Value -= 2
elseif script.Parent.Sistemas.Taken.Value == true then
if script.Parent.Sistemas.TakenSelect.Value == "Lumber" then
Hunger.Value -= 3
end
end
end
end
until (not player.Parent)