Making an item save when bought

Hello! I am SpiralGaia and I am trying to make an item save so that, when bought, stays in your inventory and can be re-equipped whenever you feel like it.

Server Script:

local remote = game:GetService("ReplicatedStorage").ShopBuy
local items = game:GetService("ServerStorage").ShopItems
remote.OnServerEvent:Connect(function(player, item)
    if typeof(item) ~= "string" or not items:FindFirstChild(item) then
        print("Bad argument", item, typeof(item))
        return -- Just guarding against non-strings/bad name
    end
    
   local item = items[item]
   local total = player.leaderstats.Cash.Value - item.Price.Value
   if total >= 0 then
        player.leaderstats.Cash.Value = total
        item:Clone().Parent = player.Backpack
    end
end)

Local Script:

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Click:Connect(function()
			script.Parent.Parent.ShopPurchasesFrame:WaitForChild(v.TextLabel.Text).Visible = true
		end)
	end
end

I have attempted this using datastore, but it made my whole game break (no clue how?) and I reverted it ASAP, so I do not have the script with me to display.

And what is this script doing?

Purchasing an item.

30characters

Ok, but what is not working on it?

Nothing. In the post I explain how I am trying to make a save system so that the tool will not have to be rebought every time you join a new server.

Are you wanting to have leaderboards in your game? If not I recommend using datastore 2 if your not comfortable with using datastore How to use DataStore2 - Data Store caching and data loss prevention

1 Like

Oh, so make array of names of buyed items and when the player will leave (or some other event), save it by userid. I am on mobile, so sorry i cant write the code. But first, get the data store service, next get data store named Items, next, when player join, give him all items from data store at his id as key. And to save, as i saied, make some array, put there all items and save it to the key.
Edit: By items, i just mean item names for data store size save reasons.

3 Likes