So I’m trying to create a DataStore to save my Tools Names so when I rejoin I get them, but saving them into a Table. I did it another way and it worked but that way only Saved 1 Tool that’s why I’m trying to redo it. Here is my script:
local DSS = game:GetService("DataStoreService")
local myDataStore = DSS:GetDataStore("TDS") -- Tools Data Store
local RS = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
local ToolsTable = {}
local TableData
local SwordData
local GunData
local Backpack = Player.Backpack
local WeaponsFolder = RS.Weapons
local Success, ErrorMsg = pcall(function()
TableData = myDataStore:GetAsync(Player.UserId.."TOOLSKEY")-- Our datastore keys
SwordData = myDataStore:GetAsync(Player.UserId.."GunKey")
SwordData = myDataStore:GetAsync(Player.UserId.."SwordKey")
end)
if Success then
print("Data successfully gotten")
for i,v in pairs(ToolsTable) do
if WeaponsFolder:FindFirstChild(v) then
WeaponsFolder[v]:Clone().Parent = Player.Backpack
end
end
else
print("Error while getting data")
warn(ErrorMsg)
end
game.Players.PlayerRemoving:Connect(function(Player)
local Success, ErrorMsg = pcall(function()
myDataStore:SetAsync(Player.UserId.."TOOLSKEY", ToolsTable)
myDataStore:SetAsync(Player.UserId.."GunKey", table.find(ToolsTable, WeaponsFolder.Pistol.Name))
myDataStore:SetAsync(Player.UserId.."SwordKey", table.find(ToolsTable, WeaponsFolder.ClassicSword.Name))
end)
if Success then
print("Data saved")
else
print("Error saving data")
warn(ErrorMsg)
end
end)
Backpack.ChildAdded:Connect(function(Child)
print("added child")
for i,T in pairs(WeaponsFolder:GetChildren()) do
if Child.Name == T.Name then
print("new tool")
table.insert(ToolsTable, Child.Name)
end
end
end)
end)
end)
Everything prints besides the “if Success then” and "else print(“Error while saving data”) those don’t print when I leave, only in studio though. Idk if it prints in the actually game but I know everything else does.
Me getting the tool
Me after rejoining