[Download Starter Project]
leaderstats
local Players = game.Players
function leaderboard(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats
end
Players.PlayerAdded:Connect(leaderboard)
OrderScript
local Food = script.Parent
local Prompt = Food.ProximityPrompt
local Waiting = Food.Waiting.Value
local WaitingScript = Food.WaitingGui.WaitingScript
local ServerStorage = game:GetService("ServerStorage")
local CanTrigger = true
function Order(Player)
if CanTrigger == true then
CanTrigger = false
Prompt.Enabled = false
local FoodName = Food.Name
local FoodClone = ServerStorage.FoodList[FoodName]:Clone()
WaitingScript.Enabled = true
wait(Waiting)
FoodClone.Parent = Player.Backpack
Prompt.Enabled = true
CanTrigger = true
end
end
Prompt.Triggered:Connect(Order)
Main Script
local Door = game.Workspace.Door
local Deliver = Door.Deliver
local Open = game.Workspace.Open
local OrderingList = game.Workspace.OrderingList
local PriceList = game.Workspace.PriceList
function Delivering(Player)
-- find leaderstats
local leaderstats = Player.leaderstats
local Money = leaderstats.Money
Open.Value = true
-- find all the food in the backpack
for _,Food in pairs(Player.Backpack:GetChildren()) do
if Food.Name == "Bento" then
if OrderingList.Bento.Value > 0 then
OrderingList.Bento.Value -= 1
Money.Value += PriceList.Bento.Value
end
Food:Destroy()
end
end
for _,Food in pairs(Player.Backpack:GetChildren()) do
if Food.Name == "Pizza" then
if OrderingList.Pizza.Value > 0 then
OrderingList.Pizza.Value -= 1
Money.Value += PriceList.Pizza.Value
end
Food:Destroy()
end
end
for _,Food in pairs(Player.Backpack:GetChildren()) do
if Food.Name == "Noodle" then
if OrderingList.Noodle.Value > 0 then
OrderingList.Noodle.Value -= 1
Money.Value += PriceList.Noodle.Value
end
Food:Destroy()
end
end
-- Pricing
if OrderingList.Bento.Value > 0 then
Money.Value -= OrderingList.Bento.Value * PriceList.Bento.Value
elseif OrderingList.Bento.Value < 0 then
Money.Value -= -OrderingList.Bento.Value * PriceList.Bento.Value
end
if OrderingList.Pizza.Value > 0 then
Money.Value -= OrderingList.Pizza.Value * PriceList.Pizza.Value
elseif OrderingList.Pizza.Value < 0 then
Money.Value -= -OrderingList.Pizza.Value * PriceList.Pizza.Value
end
if OrderingList.Noodle.Value > 0 then
Money.Value -= OrderingList.Noodle.Value * PriceList.Noodle.Value
elseif OrderingList.Noodle.Value < 0 then
Money.Value -= -OrderingList.Noodle.Value * PriceList.Noodle.Value
end
end
Deliver.Triggered:Connect(Delivering)
-- OpenOrder
function OpenOrder()
if Open.Value == true then
OrderingList.Bento.Value = 0
OrderingList.Pizza.Value = 0
OrderingList.Noodle.Value = 0
else
OrderingList.Bento.Value = math.random(0,2)
OrderingList.Pizza.Value = math.random(0,2)
OrderingList.Noodle.Value = math.random(0,2)
end
end
Open:GetPropertyChangedSignal("Value"):Connect(OpenOrder)