Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dsService = game:GetService("DataStoreService")
- local ds = dsService:GetDataStore("ShopGui14")
- game.ReplicatedStorage.Remotes.BuyAll.OnServerEvent:Connect(function(player)
- local highest = 1
- for i, v in pairs(player.OwnedItems:GetChildren()) do
- local tool = game.ServerStorage.Tools:FindFirstChild(v.Name)
- if tool.ItemNumber.Value > highest then
- highest = tool.ItemNumber.Value
- end
- end
- print("Received")
- local nextnumber = highest+1
- local done = false
- repeat
- for i, v in pairs(game.ServerStorage.Tools:GetChildren()) do
- if v:FindFirstChild("ItemNumber") then
- if v.ItemNumber.Value == nextnumber then
- if player.leaderstats.Cash.Value >= v.Cost.Value then
- player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - v.Cost.Value
- local bool = Instance.new("BoolValue")
- bool.Name = v.Name
- bool.Parent = player.OwnedItems
- nextnumber = nextnumber + 1
- else
- done = true
- end
- else
- if game.ReplicatedStorage.TotalTools.Value < nextnumber then
- done = true
- end
- end
- end
- end
- until done == true
- local purchased = {}
- if nextnumber-1>highest then
- for i, name in pairs(player.OwnedItems:GetChildren()) do
- table.insert(purchased,name.Name)
- end
- ds:SetAsync(player.UserId, purchased)
- print("Doing Save")
- end
- print("Passes")
- local item
- for i, v in pairs(game.ServerStorage.Tools:GetChildren()) do
- if v.ItemNumber.Value == nextnumber -1 then
- item = v.Name
- end
- end
- game.ReplicatedStorage.Remotes.BoughtTool:FireClient(player, item)
- end)
Add Comment
Please, Sign In to add comment