Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local items = game.ReplicatedStorage:WaitForChild("ShopItems")
- local re = game.ReplicatedStorage:WaitForChild("ShopRE")
- local itemNumber = 3
- local dss = game:GetService("DataStoreService")
- local shopDS = dss:GetDataStore("DSShop")
- game.Players.PlayerAdded:Connect(function(p)
- local ls = Instance.new("Folder", p)
- ls.Name = "leaderstats"
- local cash = Instance.new("IntValue", ls)
- cash.Name = "Cash"
- cash.Value = 30000
- local pData = shopDS:GetAsync(p.UserId) or {30000}
- cash.Value = pData[1]
- table.remove(pData, 1)
- for i, data in pairs(pData) do
- items[data]:Clone().Parent = p.StarterGear
- items[data]:Clone().Parent = p.Backpack
- end
- end)
- local currentTime = os.time()
- local previousTime = shopDS:GetAsync("LastShopUpdate") or {0}
- local function createShop()
- game.ReplicatedStorage.DailyShop:ClearAllChildren()
- local newShop = {os.time()}
- local itemsToPick = items:GetChildren()
- while #newShop < itemNumber + 1 do
- local newItem = itemsToPick[math.random(1, #itemsToPick)]
- newItem:Clone().Parent = game.ReplicatedStorage.DailyShop
- table.insert(newShop, newItem.Name)
- table.remove(itemsToPick, table.find(itemsToPick, newItem))
- end
- shopDS:SetAsync("LastShopUpdate", newShop)
- end
- local function saveData(p)
- local items = {p.leaderstats.Cash.Value}
- for i, c in pairs(p.StarterGear:GetChildren()) do
- table.insert(items, c.Name)
- end
- shopDS:SetAsync(p.UserId, items)
- end
- game.Players.PlayerRemoving:Connect(saveData)
- game:BindToClose(function()
- for i, p in pairs(game.Players:GetPlayers()) do
- saveData(p)
- end
- end)
- re.OnServerEvent:Connect(function(p, item)
- if item and item.Parent == game.ReplicatedStorage.DailyShop and p.leaderstats.Cash.Value >= item.Price.Value then
- p.leaderstats.Cash.Value -= item.Price.Value
- item:Clone().Parent = p.Backpack
- item:Clone().Parent = p.StarterGear
- end
- end)
- if currentTime - previousTime[1] >= 24*60*60 then
- createShop()
- else
- for i = 2, #previousTime do
- items[previousTime[i]]:Clone().Parent = game.ReplicatedStorage.DailyShop
- end
- end
- while wait(1) do
- local previousTime = shopDS:GetAsync("LastShopUpdate")
- local timeToReset = (24 * 60 * 60 ) - (os.time() - previousTime[1])
- local hrs = math.floor(timeToReset / 60 / 60)
- local mins = string.format("%0.2i", math.floor(timeToReset / 60) - (hrs * 60))
- local secs = string.format("%0.2i", timeToReset - (hrs * 60 * 60) - (mins * 60))
- game.ReplicatedStorage.TimeForReset.Value = hrs .. ":" .. mins .. ":" .. secs
- if timeToReset <= 0 then
- createShop()
- end
- end
Add Comment
Please, Sign In to add comment