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)
My issue is, that the when i launch the test game my tool duplicates, and i don’t want that.
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)
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.
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)
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