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
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)