How do I allow players to save their in game purchases they buy with the in game currency.
My Code for purchasing an item with in game currency (cash)
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.Backpack:FindFirstChild("GravityCoil") or plr.StarterGear:FindFirstChild("GravityCoil") or game.Workspace[plr.Name]:FindFirstChild("GravityCoil") then script.Parent.Parent.TextLabel.Text = "You have already bought this item!" wait(3) script.Parent.Parent.TextLabel.Text = "SHOP" else if plr.leaderstats.Cash.Value >= 500000 then replicatedstorage.GravityCoil:Clone().Parent = plr.Backpack replicatedstorage.GravityCoil:Clone().Parent = plr.StarterGear else local cashrequired = 500000 - plr.leaderstats.Cash.Value script.Parent.Parent.TextLabel.Text = "You need "..cashrequired.." more money to buy this item" wait(3) script.Parent.Parent.TextLabel.Text = "SHOP" end end end)
I made this code to save the cash a player has in my game and it works. How would I use it to also save the in game purchases of a player.
My Purchasable Items are in replicatedstorage.
How would I make sure that the player can keep their purchase so they when they rejoin the game they still have the gear they purchased with in game currency.
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore") function PlayerEntered(player) repeat wait() until player.Character local stats = Instance.new("IntValue") stats.Parent = player stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Parent = stats cash.Name = "Cash" if CashStore:GetAsync("Points_"..player.Name) ~= nil then cash.Value = CashStore:GetAsync("Points_"..player.Name) else cash.Value = 0 end cash.Changed:connect(function(Val) CashStore:SetAsync("Points_"..player.Name, Val) end) end game.Players.PlayerAdded:connect(PlayerEntered)
Thank You and help is appreciated