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.