Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my gamepass script not working? : -) Please send help if you have time

So, a few weeks ago i tried challenging myself by creating a game-pass script. It does not prompt me?

Here's the Code

local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local PromptSpeed = game.Workspace:WaitForChild("PromptSpeed")
local PromptBox = game.Workspace:WaitForChild("PromptPart")
local PromptPower = game.Workspace:WaitForChild("PromptJump")
local PromptVip = game.Workspace:WaitForChild("PromptVIP")

local function OnPromptPurchase(player, gamepassId, HasPass)
	
	local Humanoid = player.Parent:FindFirstChildOfClass("Humanoid")
	
	if (Humanoid) then
		player = game.Players:GetPlayerFromCharacter(player.Parent)
		
	HasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, gamepassId)	
	end
	
	if HasPass then return end
	
	if not HasPass then
		PromptSpeed.Touched:Connect(function(player)
			MarketPlaceService:PromptGamePassPurchase(player, 8638546)
			end)
				
				if not HasPass then
					PromptBox.Touched:Connect(function(player)
						MarketPlaceService:PromptGamePassPurchase(player, 8582273)
				end)
					if not HasPass then
						PromptPower.Touched:Connect(function(player)
							MarketPlaceService:PromptGamePassPurchase(player, 8796152)
					end)
						if not HasPass then
							PromptVip.Touched:Connect(function(player)
								MarketPlaceService:PromptGamePassPurchase(player, 8757181)
						end)
					end
					end
					end
					end
					end
				
				

1 answer

✓ Accepted answer

Make sure you put this in the local script and I optimized you script. To learn more about gamepasses visit: https://developer.roblox.com/en-us/api-reference/class/MarketplaceService

local MarketPlaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players") -- make sure you have the same variable
HasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)   
    

local PromptSpeed = game.Workspace:WaitForChild("PromptSpeed")
local PromptBox = game.Workspace:WaitForChild("PromptPart")
local PromptPower = game.Workspace:WaitForChild("PromptJump")
local PromptVip = game.Workspace:WaitForChild("PromptVIP")

local function OnPromptPurchase(player, gamepassid, HasPass)

    local Humanoid = player.Parent:FindFirstChildOfClass("Humanoid")

    if (Humanoid) then
        player = game.Players:GetPlayerFromCharacter(player.Parent)

    HasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, gamepassId)   
    end

    if HasPass then return end

    if not HasPass then
        PromptSpeed.Touched:Connect(function(player)
            MarketPlaceService:PromptGamePassPurchase(player, 8638546)
            end)

                if not HasPass then
                    PromptBox.Touched:Connect(function(player)
                        MarketPlaceService:PromptGamePassPurchase(player, 8582273)
                end)
                    if not HasPass then
                        PromptPower.Touched:Connect(function(player)
                            MarketPlaceService:PromptGamePassPurchase(player, 8796152)
                    end)
                        if not HasPass then
                            PromptVip.Touched:Connect(function(player)
                                MarketPlaceService:PromptGamePassPurchase(player, 8757181)
                        end)
                    end
                    end
                    end
                    end
                    end
end

2 comments

0

If I helped you please Upvote

0

I do not genuinely understand. At line 2 you are saying i need to insert my gamepassId, even though i have multiple gamepasses

This discussion is preserved as it was. New answers, comments, and votes are closed.