I am trying to make a Hunger Thirst System and i cannot figure out how to limit the value on 100. so that a player cannot be 115 full of water.
This is the code that i have:
01 | local Player = game.Players.LocalPlayer |
02 | local leaderboard = Player:WaitForChild( "Leaderboard" ) |
03 | local Tool = script.Parent |
04 |
05 | Tool.Equipped:Connect( function (mouse) |
06 | mouse.Button 1 Down:Connect( function () |
07 | leaderboard.Thirst.Value = leaderboard.Thirst.value + 15 |
08 | Tool:Destroy() |
09 | end ) |
10 | end ) |
You need to check if the value is smaller then 100 before adding this thirst value.
01 | local Player = game.Players.LocalPlayer |
02 | local leaderboard = Player:WaitForChild( "Leaderboard" ) |
03 | local Tool = script.Parent |
04 |
05 | Tool.Equipped:Connect( function (mouse) |
06 | mouse.Button 1 Down:Connect( function () |
07 | if leaderboard.Thirst.Value < 100 then -- Checking if the value is smaller then 100 |
08 | leaderboard.Thirst.Value = leaderboard.Thirst.value + 15 |
09 | Tool:Destroy() |
10 | end |
11 | end ) |
12 | end ) |
This code should work fine.