Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Auto Save/Load Script not working?

Asked by 8 years ago

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 :))

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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.

0
Ah thanks :) Bubbles5610 217 — 8y
Ad

Answer this question