Advertisement
Guest User

h

a guest
Sep 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 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.Value
  10.     local playerThirst = guivitals.Thirst.ThirstScript.ThirstValue.Value
  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 + hunger
  17.         local ifEatenThirst = playerThirst + thirst
  18.         if ifEatenThirst and ifEatenHunger < 100 then
  19.             -- Calculating portions
  20.                 local doDestroy = false
  21.                 playerMouse.Target.Portions.Value = playerMouse.Target.Portions.Value - 1
  22.                 if playerMouse.Target.Portions.Value == 0 then
  23.                 doDestroy = true
  24.             -- Giving the player their stats
  25.             playerHunger = playerHunger + hunger
  26.             playerThirst = playerThirst + thirst
  27.             print(game.Players.LocalPlayer.Name.. " has eaten ".. playerMouse.Target.Name)
  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.             else
  37.                 end
  38.             end
  39.         end
  40.     end
  41. end
  42.  
  43.  
  44. -- Running the function
  45.    
  46. script.Parent.Equipped:Connect(function(mouse)
  47.     print("Equipped eat/drink tool.")
  48.     mouse.Button1Down:Connect(EatDrink)
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement