Problem with gamepass script

local module = require(script.Parent.Parent.SettingsForGamepassPad)
local Gamepass = module.GamepassId
local mp = game:GetService("MarketplaceService")
local purchased = false
local tool = module.TheTOol


script.Parent.Touched:Connect(function(player)
	local playerPerson = game.Players:GetPlayerFromCharacter(player.Parent)
	if player.Parent and player.Parent:FindFirstChild("Humanoid") then

		local haspass2 = pcall(function()
			local success,message = mp:UserOwnsGamePassAsync(player.UserId,Gamepass)
		end)
		if not haspass2 then
			mp:PromptGamePassPurchase(playerPerson,Gamepass)
			
		else 
			local clonedTool = tool:Clone()
			clonedTool.Handle.Transparency = 0
			clonedTool.Handle.Anchored = false
			clonedTool.Parent = player.BackPack
		end
	
		
		
	end


end)



it does not give the tool and just prompts the gamepass menu again for some reason

NO ERRORS ALSO

The reason that this bug is occurring is because technically there hasn’t been a problem, the Http call to check whether the User owns the gamepass was successful. Therefore, the way to get around it is to set a variable that could be accessed from the code inside and forward to the pcall, and after that do the if statement.

local module = require(script.Parent.Parent.SettingsForGamepassPad)
local Gamepass = module.GamepassId
local mp = game:GetService("MarketplaceService")
local purchased = false
local tool = module.TheTOol


script.Parent.Touched:Connect(function(player)
	local playerPerson = game.Players:GetPlayerFromCharacter(player.Parent)
	if player.Parent and player.Parent:FindFirstChild("Humanoid") then


		local haspass2
        pcall(function()
			haspass2 = mp:UserOwnsGamePassAsync(player.UserId,Gamepass) or false -- // In case any error occurs, it sets it to false. You could also initially set the variable to be equal to false, but the call might return nil, and mess up the code. I just suggest using this method instead.
		end)

		if not haspass2 then
			mp:PromptGamePassPurchase(playerPerson,Gamepass)
			
		else 
			local clonedTool = tool:Clone()
			clonedTool.Handle.Transparency = 0
			clonedTool.Handle.Anchored = false
			clonedTool.Parent = player.BackPack
		end
	
		
		
	end


end)

This still does not give the tool

Do you own that gamepass? Maybe try to add some debug prints in the code.

I do but the code prints that I do not for some reason but the gui which pops up says diff

I changed some things and that got fixed but image
This happened ^

Even though clearly the part has it image

should I put the tool in serverstorage or smthin

Does handle exist?
If yes, it could rarely happen because the Handle hasn’t yet been loaded.
Try to maybe do:

local clonedTool = tool:Clone() 
clonedTool:WaitForChild("Handle", math.huge)
clonedTool.Handle.Transparency = 0
clonedTool.Handle.Anchored = false
clonedTool.Parent = player.BackPack
1 Like

How do I make it so that the thing only gives 1 tool

Check the player’s backpack and character to see if they already have it

1 Like

Try to put the tool in serverstorage and not make the script reach the tool through a module. Try making line 5:

local tool = game.ServerStorage.TheT0ol

or if that doesn’t work:

local tool = game:GetService(“ServerStorage”).TheT0ol