Script works, then it doesn't?

I made this script in order to give a player the boombox when they purchase the gamepass. I bought it in order to test it. Occasionally I receive the boombox in my inventory while in the game, and sometimes it doesn’t give me the item in the inventory.

Here is the script:

game.Players.playerAdded:connect(function(player)
	while true do
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, 17355562) then
		if player.Backpack:FindFirstChild("BoomBox") == nil and player.Character:FindFirstChild("BoomBox") == nil then
			local c = game.ReplicatedStorage:FindFirstChild("BoomBox"):Clone()
			c.Parent = player.Backpack
			end
		end
		wait(1)
	end
end)

Try this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local BoomBox = ReplicatedStorage:WaitForChild("BoomBox")
local GamepassId = 17355562

Players.PlayerAdded:Connect(function(player)
	while wait(1) do
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
			if 
				player.Backpack:FindFirstChild("BoomBox") or 
				player.Character:FindFirstChild("BoomBox") 
			then
				return
			end
			
			BoomBox:Clone().Parent = player.Backpack
			BoomBox:Clone().Parent = player.StarterGear
		end
	end	
end)

Worked! Thanks for the help! I think it might’ve been a flaw in the way I wrote the script.

1 Like

You are welcome! Happy to help!