– Generate blocks
local numberOfBlocks = #game:GetService(“ServerStorage”):WaitForChild(“ToolModels”):GetChildren()
local studGap = 9 – Gap between each box
local tools = game.ServerStorage.ToolModels:GetChildren()
local numberInOrders = {}
local debounce = false
local box = game.Workspace:WaitForChild(“ItemRoller”).Box0
table.sort(tools,
function(a, b)
return a.Information.Cost.Value < b.Information.Cost.Value
end
)
for i = 1,numberOfBlocks-1,1 do
newbox = box:Clone()
newbox:SetPrimaryPartCFrame(newbox.PrimaryPart.CFrame * CFrame.new(16*i,0,0))
newbox.Name = “Box”…i
newbox.Parent = game.Workspace.ItemRoller
end
for i, v in pairs(tools) do
if v then
new = v:Clone()
new:SetPrimaryPartCFrame(game.Workspace.ItemRoller[“Box”…i-1].Hitbox.CFrame)
new.Parent = game.Workspace.ItemRoller[“Box”…i-1]
end
end
game.ReplicatedStorage:WaitForChild(“RequestInformation”).OnServerInvoke = function(plr,item)
local data = {}
local bought = false
local description = game.ServerStorage.ToolModels[item.Name].Information.Description.Value
local title = item.Name
local cost = game.ServerStorage.ToolModels[item.Name].Information.Cost.Value
local costType = game.ServerStorage.ToolModels[item.Name].Information.CostType.Value
if game.ServerStorage.PlayerTools[plr.Name]:FindFirstChild(item.Name) then
– They have bought it
bought = true
else
bought = false
end
table.insert(data,1,title)
table.insert(data,2,description)
table.insert(data,3,cost)
table.insert(data,4,costType)
table.insert(data,5,bought)
return data
end
game.ReplicatedStorage.CreateTransaction.OnServerInvoke = function(player,item) – Item name, not object
local money = game.Players[player.Name].leaderstats.Cash
local cost = game.ServerStorage.ToolModels[item].Information.Cost
print(money.Value)
print(cost.Value)
if money.Value >= cost.Value and not game.ServerStorage.PlayerTools[player.Name]:FindFirstChild(item) then
– Success and the player has enough money
money.Value = money.Value - cost.Value
player.Character.Humanoid:UnequipTools()
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool.Name == player.Equipped.Value then
tool:Destroy()
end
end
player.Equipped.Value = item
local tool = game.ServerStorage.Tools:FindFirstChild(item):Clone()
tool.Parent = game.ServerStorage.PlayerTools[player.Name]
local tool = game.ServerStorage.Tools:FindFirstChild(item):Clone()
tool.Parent = player.Backpack
return true
elseif cost.Value > money.Value and not game.ServerStorage.PlayerTools[player.Name]:FindFirstChild(item) then
– They don’t have enough money
return “not enough cash”
else
return “already bought”
end
end
game.ReplicatedStorage.GetToolsBought.OnServerInvoke = function(player)
local tools = {}
for i, tool in pairs(game.ServerStorage.PlayerTools[player.Name]:GetChildren()) do
table.insert(tools,tool.Name)
end
return tools
end
game.ReplicatedStorage.EquipTool.OnServerEvent:Connect(function(player,toolName)
player.Character.Humanoid:UnequipTools()
if player.Equipped.Value ~= nil then
if player.Backpack:FindFirstChild(player.Equipped.Value) then
player.Backpack[player.Equipped.Value]:Destroy()
end
end
player.Equipped.Value = toolName
local tool = game.ServerStorage.Tools:FindFirstChild(toolName):Clone()
tool.Parent = player.Backpack
end)
game.ReplicatedStorage.CloseShop.OnServerEvent:Connect(function(player)
game.Workspace[player.Name].HumanoidRootPart.CFrame = game.Workspace.TPPart.CFrame
game.Workspace[player.Name].Humanoid.WalkSpeed = 16
wait(2)
player.InShop.Value = false
end)