function saveWeapons(player) local bin = player.StarterGear local stuff = player.Backpack:GetChildren() for i = 1,#stuff do local name = stuff[i].Name if game.StarterPack:findFirstChild(name)==nil and player.StarterGear:findFirstChild(name)==nil then stuff[i]:Clone().Parent = bin end end local char = player.Character:GetChildren() for i = 1,#char do if char[i].className == "Tool" then local name = char[i].Name if game.StarterPack:findFirstChild(name)==nil and player.StarterGear:findFirstChild(name)==nil then char[i]:Clone().Parent = bin end end end end function onRespawned(player) local findBin = game.Lighting:findFirstChild(player.Name) if findBin~=nil then local stuff = findBin:GetChildren() for i = 1,#stuff do stuff[i]:Clone().Parent = player.Backpack end findBin:Remove() end saveWeapons(player) end function onPlayerEntered(newPlayer) newPlayer.Changed:connect(function (property) if (property == "Character") then onRespawned(newPlayer) end end) while true do if newPlayer.Character~=nil then break end wait() end saveWeapons(newPlayer) end game.Players.PlayerAdded:connect(onPlayerEntered)
I Do have errors , (this is not a lcoal script), about 'startergear is not a valid member of player' for some reason. Works in studio . thanks , all help appreciated :))
When a player first joins online, their contents load after PlayerAdded
is fired. Use WaitForChild
to retrieve StarterGear
instead of indexing it directly, because it may not exist yet.