Tools being duplicated when owning a gamepass after launching the game

So first of all, im a very noob scripter so, i found this script and i wanted to it to modify to my stuff. This script is about giving a tool to a gamepass owner. (I own the gamepass due being a group game)

  1. My issue is, that the when i launch the test game my tool duplicates, and i don’t want that.
    image

  2. i tried looking it up but nothing helped me so far.

This is the Script

local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassId = 12107827
local Tool = game.ServerStorage["AK47"]

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			local ToolClone = Tool:Clone()
			ToolClone.Parent = Player.Backpack
		end
	end)
end)

Try checking if the player already has the tool

Have you left a duplicate AK47 tool in StarterPack?

Nope, only starter pack has only “Saludo” and “Descanso” as you see on the picture.

Okay well then try my suggestion

Nope it doesn’t, as i checked, the tool is only on ServerStorage. nothing else around.

I think he means print like whenever you give the tool and then if it prints once the issue is somewhere else if it prints twice your issue is there.

somewhat like that, the scripts gives you the gamepass owner an copy from the storage an ak47, but somehow it duplicates itself, also the 2nd copy doesn’t do anything.

Did you do what I said? because if so I need to know how many times it printed.

Just check if the player already has the tool inside his backpack, if he does then cancel the code :

 local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassId = 12107827
local Tool = game.ServerStorage["AK47"]

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
            if Player.Backpack:FindFirstChild(Tool) then
               print(Player.Name.." already has this tool...") -- or just return nil
            else
			   local ToolClone = Tool:Clone()
			   ToolClone.Parent = Player.Backpack
            end
		end
	end)
end)

Or if you find it twice, destroy one.

It printed only once, i think the only solution i think is removing the 2nd one from the backpack…

Doesn’t work for me. The 2 weapons are still there.

Make sure you don’t have another script somewhere running the same thing. I tested what you have and it works perfectly.

i will try to test with another tool.

I tried, it happens with every tool, i even made one. but still the same thing… i think something is doing with my tools but no t sure which thing is.

Try the script in a new baseplate, you most likely have another script running this code.

I found this

local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local gamePassID = 13192746

function Spawned(player)

local HasGamepass = false

local success, message = pcall(function()
	HasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
end)

if not success then
	warn("Checking In Player Has Gamepass" .. tostring(message))
	return
end

if HasGamepass == true then
	game.ServerStorage.M9Beretta:Clone().Parent = player.Backpack   --No spaces !!!
end 

end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
Spawned(player)
end)
end)

Players.PlayerSpawned:Connect(Spawned)

Does this have to do something with it? it was under the gun. on server storage.

You had the script under the gun? If that is the case, then that could be your problem.

I tried publishing into roblox, seems that the problem was roblox studio, because on roblox itself worked as i wanted.