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

Backpack isn't a valid member of Player?

Asked by
Nidoxs 190
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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")
0
Thanks, Kenetec! Talented scripter you are. Nidoxs 190 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

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

newPlayer.CharacterAdded:wait()
wait(1)

Answer this question