So the player will purchase an item from the shop, which needs to be given to the player in such a way that it will stay in the backpack, even if they reset.
Backpack doesn't work, because it resets when the player dies.
Also, StarterGear doesn't work, because then every player will get the item.
I'm stumped...
Here's my code (temporarily using the Backpack):
leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats") function onClickEvent() print(game.Players.LocalPlayer.Name.." is attempting a purchase.") if leaderstats.Tokens.Value < 0 then print("Not enough tokens!") script.Error:Play() else print("Ok!") leaderstats.Tokens.Value = leaderstats.Tokens.Value - 1500 local purchasedItem = game.ReplicatedStorage.Items.ClassicLauncher:Clone() purchasedItem.Parent = game.Players.LocalPlayer:WaitForChild("Backpack") end end script.Parent.MouseButton1Click:Connect(onClickEvent)
I suggest you :Clone() items from ServerStorage into the player's backpack after they die, aka when their character loads.
-- server script in ServerScriptService local boughtItems = { game.ServerStorage.Items.Item1; game.ServerStorage.Items.Item2; } game:GetService("Players").PlayerAdded:Connect(function(p) p.CharacterAdded:connect(function() for a,b in next, boughtitems do b:Clone().Parent=p:WaitForChild("Backpack") end end) end)
You should clone the tool to the backpack, plus another one to THAT players starter gear.
leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats") function onClickEvent() print(game.Players.LocalPlayer.Name.." is attempting a purchase.") if leaderstats.Tokens.Value < 0 then print("Not enough tokens!") script.Error:Play() else print("Ok!") leaderstats.Tokens.Value = leaderstats.Tokens.Value - 1500 local purchasedItem = game.ReplicatedStorage.Items.ClassicLauncher:Clone() local purchasedItem2 = game.ReplicatedStorage.Items.ClassicLauncher:Clone() purchasedItem.Parent = game.Players.LocalPlayer:WaitForChild("Backpack") purchasedItem2.Parent = game.Players.LocalPlayer:WaitForChild("StarterGear") end end script.Parent.MouseButton1Click:Connect(onClickEvent)
and btw, you should do these things on client side. Only the client would see the leaderstats change. You should use remote events to make it seen to the server.
local savedBackpack = {} -- Creating a table for our backpack, we'll iterate through this later. local Player = game:GetService("Players").LocalPlayer -- When the user purchases an item, local purchasedItem = game.ReplicatedStorage.Items.ClassicLauncher:Clone() purchasedItem.Parent = game.Players.LocalPlayer:WaitForChild("Backpack") table.insert(savedBackpack, purchasedItem); -- When the player dies, for _,v in pairs(savedBackpack) do v.Parent = Player:WaitForChild("BackPack") end
Please for the love of god use tables for this, don't parent anything to a storage like others have sugguested.
--put in ServerScriptService local Storage = Instance.new("Folder") Storage.Parent = game:GetService("ServerStorage") Storage.Name = "Storage" game:GetService("Players").PlayerAdded:connect(function(plr) if not Storage:FindFirstChild(plr.Name) then --Creates player storage local Folder = Instance.new("Folder") Folder.Parent = Storage Folder.Name = plr.Name end plr.CharacterAdded:connect(function(char) for i,v in pairs(Storage[plr.Name]:GetChildren()) do --Loads player data v.Parent = char end char.Humanoid.Died:connect(function() for i,v in pairs(char:GetChildren()) do --Saves player data if v:IsA("Tool") then v.Parent = Storage end end end) end) end) game:GetService("Players").PlayerRemoving:connect(function(plr) pcall(function() Storage[plr.Name]:Destroy() --Removes player data end) end)