this is my script and whenever i put the tools in my backpack and rejoin, the tools will pop back up in my starterpack(toolbar)
local itemsFolder = game:GetService('ServerStorage'):WaitForChild('Items')
local players = game:GetService('Players')
local dataStoreService = game:GetService('DataStoreService')
local mainStore = dataStoreService:GetDataStore('Main')
local function playerAdded(plr)
repeat
task.wait()
until plr.Character
task.wait(0.1)
local success, inventory = pcall(function()
return mainStore:GetAsync(plr.UserId)
end)
if success and inventory then
for _, name in pairs(inventory) do
local item = itemsFolder:FindFirstChild(name)
if item then
local clone = item:Clone()
clone.Parent = plr.Backpack
end
end
end
end
local function playerLeft(plr)
local backpack = plr.Backpack
local char = plr.Character
local itemsTab = {}
if char then
for _, object in pairs(char:GetChildren()) do
if object:IsA('Tool') then
table.insert(itemsTab, object.Name)
end
end
end
for _, object in pairs(backpack:GetChildren()) do
if object:IsA('Tool') then
table.insert(itemsTab, object.Name)
end
end
local success, err = pcall(function()
return mainStore:SetAsync(plr.UserId, itemsTab)
end)
if not success then
warn("Error saving data for player " .. plr.UserId .. ": " .. err)
end
end
players.PlayerAdded:Connect(playerAdded)
players.PlayerRemoving:Connect(playerLeft)