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

Player's Backpack doesn't receive tools from script, what's the problem?

The following code uses a "for" loop to clone game.ServerStorage.Tools.Donut (a tool) and give it to a player who joined the game:

game.Players.PlayerAdded:Connect(function(client)
	for i = 1, 3 do 
		repeat wait()
		until client:FindFirstChild("Backpack") 
		local donut = game.ServerStorage.tools.Donut:Clone()
		donut.Parent = client.Backpack
	end
end)

This didn't work, so I tried putting wait() once the client joins

game.Players.PlayerAdded:Connect(function(client)
	wait(5)
	for i = 1, 3 do 
		repeat wait()
		until client:FindFirstChild("Backpack") 
		local donut = game.ServerStorage.tools.Donut:Clone()
		donut.Parent = client.Backpack
	end
end)

This worked, though. I'm not sure why it's like this. Is it because the player's Character needs to be loaded for them to recieve the tools?

1 answer

✓ Accepted answer

I hope this helped

game.Players.PlayerAdded:Connect(function(client)
	    wait(5)
	    for i = 1, 3 do
			-- under this will wait until the character is loaded to receive tools    	
			repeat until client.Character:FindFirstChild("HumanoidRootPart")
	        until client:FindFirstChild("Backpack")
	        local donut = game.ServerStorage.tools.Donut:Clone()
	        donut.Parent = client.Backpack
	   end
end)

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