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

script wont give me item when gamepass is owned?

game.Players.PlayerAdded:Connect(function(player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, 8979366) then
		if player.Backpack:FindFirstChild("BoomBox") == nil and player.Character:FindFirstChild("BoomBox") == nil then
			local r = game.Lighting:FindFirstChild("BoomBox"):Clone()
			r.Parent = player.Backpack
		end
	end
end)

I put a Boombox inside Lighting and 8979366 is the gamepass id

1 answer

✓ Accepted answer

You want to wait until the player's character is added, and you want to add the boombox every time the player's character is added. This should solve your issue.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, 8979366) then
			if player.Backpack:FindFirstChild("BoomBox") == nil and char:FindFirstChild("BoomBox") == nil then
				local r = game.Lighting:FindFirstChild("BoomBox"):Clone()
				r.Parent = player.Backpack
			end
		end
	end)
end)

1 comment

0

Also capitalize the U in UserId.

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