I don’t really get into data saving to often, however I am currently trying to save swords in an inventory, however it won’t work, there are no errors in output currently occurring, here is the script, if you maybe know a fix it would be greatly appreciated, thanks:
local dataStoreService = game:GetService("DataStoreService")
local toolsDataStore = dataStoreService:GetGlobalDataStore("toolsData")
local loaded = {}
game.Players.PlayerAdded:Connect(function(plr)
local plrswords = plr:WaitForChild("Swords")
local serverswords = game.ServerStorage.Swords
if plr.UserId > 0 and plr.Parent then
local swordsdata = toolsDataStore:GetAsync(plr.UserId)
if swordsdata ~= "Request Rejected" then
if swordsdata then
print(swordsdata)
for i,sword in ipairs(serverswords:GetChildren()) do
local swordfound = swordsdata[sword.Name]
if swordfound then
sword:Clone().Parent = plrswords
end
end
end
loaded[plr] = true
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local plrswords = plr:WaitForChild("Swords")
if plrswords then
if loaded[plr] then
local swordsdata = {}
print(plrswords:GetChildren())
for i,sword in ipairs(plrswords:GetChildren()) do
table.insert(swordsdata, sword.Name)
end
toolsDataStore:SetAsync(plr.UserId, swordsdata)
end
end
loaded[plr] = nil
end)