How do I add a tool to gamepass?

Hello! Could someone help me with a tutorial or code example to know how to add my tool to a gamepass, please?

Project image:

tool:
image

gui:
image

Localscript tool:

local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
end)

local isActivated = false

UID.InputBegan:Connect(function(key,isTyping)
	if equipped == true then
		print("tool equipped")
		if key.KeyCode == Enum.KeyCode.N then
			isActivated = not isActivated
			if (isActivated) then
				pcall(function()
					local StarterGui = game:GetService("StarterGui")
					StarterGui:SetCore("TopbarEnabled", false)
				end)

				local frame = game:GetService("Players").LocalPlayer.PlayerGui
				print("Activated.")
				-- Config 1
				wait(.1)
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.1
				wait(.1)
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.15
				-- Config 2
				wait(.1)
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.25
				wait(.1)
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.4
				wait(.1)
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.6	
			else	
				pcall(function()
					local StarterGui = game:GetService("StarterGui")
					StarterGui:SetCore("TopbarEnabled", true)
				end)
				local frame = game:GetService("Players").LocalPlayer.PlayerGui
				frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 1
				print("no activated.")
			end
		end
	end
end)

I highly recommend using UserOwnsGamePassAsync and PlayerAdded mixed with CharacterAdded. put the tool in ServerStorage and Clone the tool in to the Backpack

Put this example in a Server Script in ServerScriptStorage

    local gamepassid = "" --Make this the gamepass ID.

game.Players.PlayerAdded:Connect(function(plr)
	
	plr.CharacterAdded:Connect(function()
	
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepassid) then
		
			game.ServerStorage.Tool:Clone().Parent = plr.Backpack
		
		end
		
	end)
	
end)
1 Like

I had to edit so many mistakes I forgot before I posted lol

You should use MarketPlaceService And UserOwnsGamepassAsync

--ServerScriptService Script
local MarketPlaceService = game:GetService("MarketplaceService")

local gamepassId = GamepassId
local Tool1 = script.Your Tool --Reminder make sure to put the item into this script 

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
			Tool1:Clone()
			Tool1.Parent = Player.Backpack
		end
	end)
end)
2 Likes

Thanks you bro!! :smiley: :smiley: :smiley:

1 Like

bro how I legit did the exact same thing and you got the Solution smh