I’ve been working on a case opening system. When the case is opened it puts and item in your inventory GUI. I’ve been trying to save that. but it isn’t working. I’ve tried storing a table and using SetAsync to save it.
This is the local script code:
local owns = {}
local times = 0
local number = 0 -- Might need to change
local items = require(game.ReplicatedStorage.Items)
local price = 1000
local time = 2.5
local debounce = true
local player = game.Players.LocalPlayer
local case = require(game.StarterGui.Modules.case)
local Item1 = player.PlayerGui.Inventory.Frame.Item1
script.Parent.MouseButton1Click:connect(function()
if player.leaderstats.Eggs.Value >= price then
if debounce == true then
player.leaderstats.Eggs.Value = player.leaderstats.Eggs.Value - price
debounce = false
local a = require(game.Players.LocalPlayer("WaitForChild","PlayerGui")("WaitForChild","Modules")("WaitForChild","case")):create("Classic")
if Item1.Visible == false then
Item1.Text = tostring(a)
player.PlayerGui.Inventory.Frame.Item1.Visible = true
table.insert(owns, Item1)
else
number = number + 2
local Item = Item1:clone()-- Might need to change
Item.Text = tostring(a)
Item.Position = UDim2.new(.097 * number,0,.08 * times,0)-- Might need to change
Item.Parent = Item1.Parent
table.insert(owns, Item)
if number == 10 then
number = 0
times = times + 1
Item.Position = UDim2.new(.097 * number,0,.08 * times,0)
end
end
game.ReplicatedStorage.save:FireServer(player.UserId, owns)
print(a)
wait(time)
debounce = true
end
end
end)
This is where the Remote function fires:
local DataStore = game:GetService("DataStoreService"):GetDataStore("ownsData")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local PlayerData = DataStore:GetAsync(tostring(player.UserId))
if PlayerData ~= nil then
print(PlayerData)
PlayerData.Parent = player.PlayerGui.Inventory.Frame
end
end)
game.ReplicatedStorage.save.OnServerEvent:Connect(function(UserId, owns)
DataStore:SetAsync(tostring(UserId), owns)
end)