I want to make the items that have been bought from the shop save from the datastore but for some reason the script won’t work. However, the script has no errors or warnings.
local DataStoreService = game:GetService('DataStoreService')
local SaveData = DataStoreService:GetDataStore('testdata2')
local ToolFolder = game:GetService('ReplicatedStorage'):FindFirstChild("Gears")
game.Players.PlayerAdded:Connect(function(Player)
local ShopDTA = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild('Backpack')
local StarterGear = Player:WaitForChild('StarterGear')
local Tools = Player:WaitForChild('Tools')
if ShopDTA ~= nil then
for i, v in pairs(ShopDTA) do
if ToolFolder:FindFirstChild(v) and Tools:FindFirstChild(v) == nil then -- for the unequipped weapons
ToolFolder[v]:Clone().Parent = Tools
elseif Tools:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then -- for the equipped weapons
ToolFolder[v]:Clone().Parent = Tools
ToolFolder[v]:Clone().Parent = StarterGear
ToolFolder[v]:Clone().Parent = Backpack
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild('Humanoid'):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ShopTable = {}
for i, v in pairs(Player:WaitForChild('StarterGear'):GetChildren()) do
table.insert(ShopTable, v.Name)
end
if ShopTable ~= nil then
SaveData:SetAsync(Player.UserId, ShopTable)
end
end)