I have tried and tried this, I cannot for the life of me figure it out! I have a script set up so a player can buy items, then they are taken from the replicated storage as a clone, and into the players starter gear and backpack. Here is that script
script.Parent.MouseButton1Click:connect(function()
local RS = game:GetService('ReplicatedStorage')
local item = RS:WaitForChild('GrappleHook')
local price = 0
local player = game.Players.LocalPlayer
local stats = player:WaitForChild('leaderstats')
if stats.Cash.Value >= price then
stats.Cash.Value = stats.Cash.Value - price
local cloned = item:Clone()
local cloned2 = item:Clone()
cloned2.Parent = player.Backpack
cloned.Parent = player.StarterGear
end
end)
and that works just fine,, one time. i dont want the player to have to purchase a new one everytime they die, that would be frustrating to everyone. But my problem is that when players die the tool just disappears, they have to re purchase the item. Here is the script im using to try to save the tool. Do you see any problems that could be getting in the way, any pointers you could give me? here is the data store script
local RunService = game:GetService("RunService")
local ToolData = game:GetService("DataStoreService"):GetDataStore("ToolData")
local ToolLocation = game.ServerStorage.Tools -- The location where all your tools are saved
function GetToolByName(toolName)
for _, tool in pairs(ToolLocation:GetChildren()) do
if tool.Name == toolName then return tool end
end
end
function IsRegisteredTool(tool)
for _, playerTool in pairs(ToolLocation:GetChildren()) do
if playerTool.Name == tool.Name then return true end
end
end
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player.Character
local dataKey = "tool-data_"..player.UserId
if ToolData:GetAsync(dataKey) then
for i, toolName in pairs(ToolData:GetAsync(dataKey)) do
local newStarterTool = GetToolByName(ToolData:GetAsync(dataKey)[i]):Clone()
local newTempTool = GetToolByName(ToolData:GetAsync(dataKey)[i]):Clone()
newStarterTool.Parent = player.StarterGear
newTempTool.Parent = player.Backpack
end
ToolData:SetAsync(dataKey, {})
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataKey = "tool-data_"..player.UserId
local playerTools = {}
for _, tool in pairs(player.StarterGear:GetChildren()) do
if tool:IsA("Tool") and IsRegisteredTool(tool) then table.insert(playerTools, 1, tool.Name) end
end
if RunService:IsStudio() or #playerTools < 1 then return end
ToolData:SetAsync(dataKey, playerTools)
end)
thanks everyone!!

3 comments
Okay ill try that real quick, ill let you know what happens, thanks!
Where would I place the 2nd script? Workspace?
The first script is where you put the purchase script(Make it FE compatible), The second one make a normal script and put it in StarterCharacterScripts