local DataStore = game:GetService("DataStoreService"):GetDataStore('ToolSave')--
game.Players.PlayerAdded:Connect(function(plr) --when the player is added to the game in the player properties
local savedstuff = DataStore:GetAsync(plr.userId)-- saved stuff variable means The Data of the player using userID
if savedstuff ~= nil then --if the data is not nil continue this script
for i,v in pairs(savedstuff) do --for i,v in pairs the Data Inventory
if game.ServerStorage.Inventory:FindFirstChild(v) ~= nil then --Try looop and try find the inventory and if its not nil then continue
local weopon = game.ServerStorage.Inventory:FindFirstChild(v):Clone() --if it isnt nil the clone it
weopon.Parent = plr:WaitForChild('Backpack')-- Puts this in the backpack
end
end
end
plr.CharacterRemoving:Connect(function()-- When character is being removed from the game
plr.Character.Humanoid:UnequipTools()-- Un equip the weopons
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)-- when player is being removed
Table = {}-- Creates a table
for i,v in pairs(plr.Backpack:GetChildren()) do-- for i,v in pairs loop around the backpacks childrens
table.insert(Table,v.Name)--insert whatever is found in the table
end
if Table ~= nil then-- if table is not nil when the player leaves the game save the game
DataStore:SetAsync(plr.userId,Table)-- if it is not equal to nil then Set the Data to that using user iD and putting table into it
end
end)
I tried doing loops when player was added but it kept giving me arg was nil does anyone know how to make a script that can save every 3 minutes or something cause i tried and it kept saying arg was nil
