Getting multiple gamepass gear depending based on the number of players in the game

I have a funky script here that keeps giving me multiples of gamepass gear based on the number of players in the game. Say there’s 16 players in the game, the gamepass owner will get 16 of the same tool.

I’m pretty sure it has something to do this with script. Anyone know how to fix this. Any help is greatly appreciated, thanks!

--SERVICE LOCALS--
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local player = Players.LocalPlayer

--ID LOCALS--
local ID_bncr = 17791929 -- boombox 500R$

--GEAR LOCALS--
local Punch = game.ServerStorage.Gear.Punch

--BOUNCER GAMEPASS--
game.Players.PlayerAdded:Connect(function(player)
	local success, message = pcall (function()
		hasPass2 = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID_bncr)
	end)

	if hasPass2  then
		for _, playerVal in pairs(game.Players:GetPlayers()) do
			print("Player has BOUNCER gamepass")

			Punch:Clone().Parent = player.Backpack
			Punch:Clone().Parent = player.StarterGear

			--GrabPlayer:Clone().Parent = player.Backpack
			--GrabPlayer:Clone().Parent = player.StarterGear
		end
	end
end)

This can be fixed by removing the for loop. Instead of your current code, just do:

--SERVICE LOCALS--
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local player = Players.LocalPlayer

--ID LOCALS--
local ID_bncr = 17791929 -- boombox 500R$

--GEAR LOCALS--
local Punch = game.ServerStorage.Gear.Punch

--BOUNCER GAMEPASS--
game.Players.PlayerAdded:Connect(function(player)
	local success, message = pcall (function()
		hasPass2 = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID_bncr)
	end)

	if hasPass2  then
		print("Player has BOUNCER gamepass")

		Punch:Clone().Parent = player.Backpack
		Punch:Clone().Parent = player.StarterGear

		--GrabPlayer:Clone().Parent = player.Backpack
		--GrabPlayer:Clone().Parent = player.StarterGear
	end
end)

Basically what was happening is every single time a player joins it loops through all the players and gives the gear. You only have to give it to the one player that joins if they have the pass. If you need anything else let me know!

1 Like