Advertisement
Guest User

Cafe Tycoon Cooking Script

a guest
Jan 2nd, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. wait()
  2. local queue = script.Parent.Queues
  3.  
  4. function addToQueue(plr, food)
  5.     local tycoon = game.Workspace:FindFirstChild(plr.Values.Tycoon.Value)
  6.     local foodData = game.ReplicatedStorage.FoodData:FindFirstChild(food)
  7.     -- Get empty slot
  8.     local slot = getEmptySlot()
  9.     if slot == nil then return "No Available Slots" end
  10.     -- If ingredients then look for them
  11.     if foodData.Ingredients.Value == true then
  12.         for _, i in ipairs(foodData.Ingredients:GetChildren()) do
  13.             if not gotIngredients(i.Name, i.Value, tycoon) then
  14.                 return "Missing Ingredients"
  15.             end
  16.         end
  17.         takeInredients(food, tycoon)
  18.     end
  19.     slot.Value = food
  20.     cook()
  21.     return "Succes"
  22. end
  23. script.RemoteCook.OnServerInvoke = addToQueue
  24.  
  25. function gotIngredients(food, amount, tycoon)
  26.     for _, i in ipairs(tycoon.Values.Food:GetChildren()) do
  27.         if i.Name == food then
  28.             if i.Value >= amount then
  29.                 return true
  30.             end
  31.         end
  32.     end
  33.     return false
  34. end
  35.  
  36. function takeInredients(food, tycoon)
  37.     for _, i in ipairs(game.ReplicatedStorage.FoodData:FindFirstChild(food).Ingredients:GetChildren()) do
  38.         tycoon.Values.Food:FindFirstChild(i.Name).Value = tycoon.Values.Food:FindFirstChild(i.Name).Value - i.Value
  39.     end
  40. end
  41.  
  42. function getEmptySlot()
  43.     if queue.Cooking.Value == "" then return queue.Cooking end
  44.     for _, i in ipairs(queue:GetChildren()) do
  45.         if i.Value == "" then
  46.             return i
  47.         end
  48.     end
  49.     return nil
  50. end
  51.  
  52. local db = false
  53. function cook()
  54.     local cooking = queue.Cooking
  55.     if cooking.Value == "" then return end -- If the value is nothing, then return
  56.     if db == true then return end
  57.     db = true  
  58.     while cooking.Progress.Value < game.ReplicatedStorage.FoodData:FindFirstChild(cooking.Value).Time.Value do
  59.         wait(0.05)
  60.         cooking.Progress.Value = cooking.Progress.Value + 0.05
  61.     end
  62.     script.Parent.Parent.Parent.Parent.Values.Food:FindFirstChild(cooking.Value).Value = script.Parent.Parent.Parent.Parent.Values.Food:FindFirstChild(cooking.Value).Value + 1
  63.     cooking.Progress.Value = 0
  64.     db = false
  65.     moveQueue()
  66. end
  67. queue.Cooking.Changed:Connect(function() cook() end)
  68.  
  69. function moveQueue()
  70.     queue.Cooking.Value = ""
  71.     wait()
  72.     queue.Cooking.Value = queue:FindFirstChild("1").Value
  73.     for v, i in ipairs(queue:GetChildren()) do
  74.         if i.Name ~= "1" and i.Name ~= "Cooking" then
  75.             queue:FindFirstChild(tonumber(i.Name) - 1).Value = i.Value
  76.         end
  77.     end
  78.     queue:FindFirstChild(queue.Value).Value = ""
  79.     cook()
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement