Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Backpack isn't a valid member of Player?

When a player joins a Gui, script and Sound is supposed to be put in their PlayerGui and Backpack. However Backpack is not a valid member of Player? Help?

local function onPlayerEntered(newPlayer)
		local a = script.Gui:Clone() 
		a.Parent = newPlayer.PlayerGui
		
		local b = script.CamFix:Clone() 
		b.Parent = newPlayer.Backpack 		
		newPlayer.Backpack.CamFix.Disabled = false
		
		local c = Instance.new("Sound") 
		c.Parent = newPlayer.PlayerGui 
		c.SoundId = "http://www.roblox.com/asset/?id=142725769" 
		c.Volume = 1 
		newPlayer.PlayerGui.Sound:Play()  
		print(newPlayer.Name)	 
end

game.Players.PlayerAdded:connect(onPlayerEntered)


for i,v in pairs (game.Players:getChildren()) do onPlayerEntered(v) end

2 answers

✓ Accepted answer

Try waiting for the Backpack and PlayerGui to be added to the Player object before you attempt to use them using the WaitForChild function.

newPlayer:WaitForChild("Backpack")
newPlayer:WaitForChild("PlayerGui")

1 comment

0

Thanks, Kenetec! Talented scripter you are.

This is what I always do at the top since WaitForChild sometimes waits for infinity:

newPlayer.CharacterAdded:wait()
wait(1)

This discussion is preserved as it was. New answers, comments, and votes are closed.