Issue With Inserting Items Into Backpacks On Joining

Issue

On Player Join, items can’t be directly inserted into a Player’s Backpack, even after making use of WaitForChild.

Reproduction Steps

  1. Open A Blank Baseplate

  2. Create A Blank Script In ServerScriptService

  3. Paste The Following Code Into The Script

    local Players = game:GetService("Players")
    
    
    Players.PlayerAdded:Connect(function(player: Player)
    	local Tool = Instance.new("Tool")
    	
    	Tool.CanBeDropped = false
    	Tool.RequiresHandle = false
    		
    	Tool.Parent = player.Backpack
    end)
    
  4. Run The Game

Workarounds

  1. Place the Tool into StarterGear

  2. Use ChildAdded events to wait for the Actual Backpack.

2 Likes

We’ve filed a ticket to our internal database, and we’ll follow up when we have an update.

Thanks for flagging!

2 Likes

This seems to be intended behavior. You need to wait for the character to load first.

Same applies to PlayerGui, if CharacterAutoLoads is false.

The problem mainly comes from the fact that there is a “fake” backpack that exists before the character loads in, and that causes problems. If they didn’t create the Backpack until the character is spawned, that would probably be better, and cause less confusion.

Well, even with that fake backpack, this functionality is the same as the PlayerGui.

Just before firing the Player.CharacterAdded event, the server will:

  1. Destroy any existing Backpack instances inside the Player
  2. Create a new Backpack instance and populate it using the contents of StarterPack and StarterGear.

In your original code, player.Backpack is referring to the pre-existing Backpack instance which is destroyed in the step 1.

Waiting for the new Backpack with ChildAdded will only solve this for the first time the player’s character is spawned.

Instead, you can listen for the Player.CharacterAdded event like this:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player: Player)
	player.CharacterAdded:Connect(function(character: Model)
		local Tool = Instance.new("Tool")

		Tool.CanBeDropped = false
		Tool.RequiresHandle = false

		Tool.Parent = player.Backpack
	end)
end)
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.