Tool only inserting into backpack half of the time on player join

When a player joins the game, I check if the player has a gamepass and if so then a tool is inserted into the player’s backpack. However, it only works about half of the time. I tried having the game wait for the tool and backpack of the player but there was no change in the results.

My code looks like this:

local mps = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(plr) -- function calls when player joins the game
	
	if mps:UserOwnsGamePassAsync(plr.UserId, 775929758) then --checks if user have gamepass
		local gloop = game.ReplicatedStorage.GloopGun:Clone() --clones from repstorage (where the original gloopgun is kept)
		gloop.Parent = plr.Backpack --puts it into the players inventory
	end
	
end)

The code is in serverscriptservice and it is a regular script.

Please give me any suggestions as to what I should do to make this more consistent

1 Like

Either check that the character has also been added or make a loading screen and insert the tool when the player has pressed play.
Alternatively repeat the attempt until the item is in the backpack.
Either way the idea is to wait till all the necessary assets have loaded prior to the attempt

1 Like

I implemented your first suggestion. Thank you for the help!

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