Advertisement
Guest User

a

a guest
Sep 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. --[Tool for eating/drinking
  2.  
  3. -- Does all the hunger and thirst n' stuff
  4. function EatDrink()
  5.     -- Local Variables
  6.     local playerMouse = game.Players.LocalPlayer:GetMouse()
  7.     local playerGui = game.Players.LocalPlayer.PlayerGui
  8.     local guivitals = playerGui.Vitals
  9.     local playerHunger = guivitals.Hunger.HungerScript.HungerValue
  10.     local playerThirst = guivitals.Thirst.ThirstScript.ThirstValue
  11.     -- Consumeable check + hunger & thirst giving values
  12.     if playerMouse.Target.Consumeable then
  13.         local hunger = playerMouse.Target.Hunger.Value
  14.         local thirst = playerMouse.Target.Thirst.Value
  15.         -- Checks for if player is eligible to eat the food
  16.         local ifEatenHunger = playerHunger.Value + hunger
  17.         local ifEatenThirst = playerThirst.Value + thirst
  18.         if ifEatenThirst and ifEatenHunger <= 100 then
  19.             -- Giving the player their stats
  20.             playerHunger.Value = playerHunger.Value + hunger
  21.             playerThirst.Value = playerThirst.Value + thirst
  22.             print(game.Players.LocalPlayer.Name.. " has eaten ".. playerMouse.Target.Name)
  23.             -- Calculating portions
  24.             local doDestroy = false
  25.             playerMouse.Target.Portions.Value = playerMouse.Target.Portions.Value - 1
  26.             if playerMouse.Target.Portions.Value == 0 then
  27.             doDestroy = true
  28.             -- UI Stuff
  29.             local hungerIncreaseBy = hunger * 4
  30.             local thirstIncreaseBy = thirst * 4
  31.             guivitals.Hunger.Size = UDim2.new(0, guivitals.Hunger.Size.X.Offset + hungerIncreaseBy, 0, guivitals.Hunger.Size.Y.Offset)
  32.             guivitals.Thirst.Size = UDim2.new(0, guivitals.Thirst.Size.X.Offset + thirstIncreaseBy, 0, guivitals.Thirst.Size.Y.Offset)
  33.             -- "To :Destroy(), or not to :Destroy(); that is the question." - William Scriptspear
  34.             if doDestroy == true then
  35.                  playerMouse.Target:Destroy()
  36.                 end
  37.             end
  38.         end
  39.     end
  40. end
  41.  
  42.  
  43. -- Running the function
  44.    
  45. script.Parent.Equipped:Connect(function(mouse)
  46.     print("Equipped eat/drink tool.")
  47.     mouse.Button1Down:Connect(EatDrink)
  48. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement