Attempting to make a Gamepass/Weapon Dialog Seller:

Hi! I’m a very amateur scripter and I’m looking to find help to complete my dialog seller. Basically the principle is that the user selects a dialog option (choice) and then if the user has the gamepass attached to the choice, the script will give the user the weapon. If they don’t have the gamepass, they will have to buy it by using the PromptPurchase function.

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

script.Parent.DialogChoiceSelected:connect(function(player, choice)
    if choice.Name == "Choice2" then
        MarketPlaceService:PromptProductPurchase(player, 7539222)
        if choice==script.Parent.Choice2 and UserStorageService(7539222) and (player.Backpack:findfirstchild("M9")==nil) then
               local m9 = game.ServerStorage["M9"]:clone()
            m9.Parent = player.Backpack

    elseif choice.Name == "Choice1" then 
            MarketPlaceService:PromptProductPurchase(player, 7699022)
            if choice==script.Parent.Choice1 and UserStorageService(7699022) and (player.Backpack:findfirstchild("MP7A1")==nil) then
                local mp7 = game.ServerStorage["MP7"]:clone()
            	mp7.Parent = player.Backpack
            end
        end
    elseif choice.Name == "Choice3" then
		MarketPlaceService:PromptProductPurchase(player, 7539220)
		if choice==script.Parent.Choice3 and UserStorageService(7539220) and (player.Backpack:findfirstchild("C4")==nil) then
                local c4 = game.ServerStorage["C4"]:clone()
            	c4.Parent = player.Backpack
            end
		end
end)

As I said, I have absolutely no idea what I’m doing and I’ve been searching for help on online forums. However, I have no idea to take this help and implement it into a dialog gamepass system.

Thanks!-

1 Like

I think what your looking for is:

UserOwnsGamePassAsync will check and see if a player has a game pass, it will return true if the player does have it and return false if they do not.

I don’t know how to implement this

1 Like

All you would need to do is set up a simple if not statement(Note All of this code was wrote right here on the devforum so it might have some mistakes)

if  not MarketPlaceService:UserOwnsGamePassAsync(player, 7539222) then
----prompt purchase 
end

i am also going to assume you forgot to check and see if the player actual bought the game pass the game pass so you also need to use:
MarketplaceService.PromptGamePassPurchaseFinished

(this code does not include MarketplaceService.PromptGamePassPurchaseFinished)

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

script.Parent.DialogChoiceSelected:connect(function(player, choice)
    if choice.Name == "Choice2" then
if  not MarketPlaceService:UserOwnsGamePassAsync(player, 7539222) then----Check and see if the player does not have the gamepass
        MarketPlaceService:PromptProductPurchase(player, 7539222)
         end
        if choice==script.Parent.Choice2 and UserStorageService(7539222) and (player.Backpack:findfirstchild("M9")==nil) then
               local m9 = game.ServerStorage["M9"]:clone()
            m9.Parent = player.Backpack

    elseif choice.Name == "Choice1" then 


if  not MarketPlaceService:UserOwnsGamePassAsync(player, 7699022) then----Check and see if the player does not have the gamepass
  MarketPlaceService:PromptProductPurchase(player, 7699022)
         end
            MarketPlaceService:PromptProductPurchase(player, 7699022)
            if choice==script.Parent.Choice1 and UserStorageService(7699022) and (player.Backpack:findfirstchild("MP7A1")==nil) then
                local mp7 = game.ServerStorage["MP7"]:clone()
            	mp7.Parent = player.Backpack
            end
        end
    elseif choice.Name == "Choice3" then

if  not MarketPlaceService:UserOwnsGamePassAsync(player,7539220) then----Check and see if the player does not have the gamepass
		MarketPlaceService:PromptProductPurchase(player, 7539220)
      end
		if choice==script.Parent.Choice3 and UserStorageService(7539220) and (player.Backpack:findfirstchild("C4")==nil) then
                local c4 = game.ServerStorage["C4"]:clone()
            	c4.Parent = player.Backpack
            end
		end
end)

To add in the finished event i would do something like this:

script.Parent.DialogChoiceSelected:connect(function(player, choice)
 if choice.Name == "Choice2" then
if  not MarketPlaceService:UserOwnsGamePassAsync then

----prompt purchase

else

local m9 = game.ServerStorage["M9"]:clone()
m9.Parent = player.Backpack


end

elseif choice.Name == "Choice1" then 
     if  not MarketPlaceService:UserOwnsGamePassAsync then
----prompt purchase

else


if choice==script.Parent.Choice1 and UserStorageService(7699022) and (player.Backpack:findfirstchild("MP7A1")==nil) then
                local mp7 = game.ServerStorage["MP7"]:clone()
            	mp7.Parent = player.Backpack
          end
        end
end


    elseif choice.Name == "Choice3" then 
if  not MarketPlaceService:UserOwnsGamePassAsync then

---prompt purchase 
else

if choice==script.Parent.Choice3 and UserStorageService(7539220) and (player.Backpack:findfirstchild("C4")==nil) then
                local c4 = game.ServerStorage["C4"]:clone()
            	c4.Parent = player.Backpack
            end


end

end

end

end

end

---Finished Event
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gamepass, Bought)

if Bought and plr then

if gamepass == (gamepassidgoeshere) then

if UserStorageService(7699022) and (player.Backpack:findfirstchild("MP7A1")==nil) then
                local mp7 = game.ServerStorage["MP7"]:clone()
            	mp7.Parent = player.Backpack
          end
     end

end

else

-------Do whatever you want to if the player does not buy the gamepass
end

end

Hopefully that gave you a better understanding! (Good luck!)

1 Like

Thank you for this but I’m still unable to get it to work!
Edited version:

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

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice.Name == "Choice1" then
		if not MarketPlaceService:UserOwnsGamePassAsync(7539222) then
			MarketPlaceService:PromptProductPurchase(player, 7539222)
		elseif choice==script.Parent.Choice1 and UserStorageService(7539222) and (player.Backpack:findfirstchild("M9")==nil) then
			local m9 = game.ServerStorage["M9"]:clone()
			m9.Parent = player.Backpack
		end

	elseif choice.Name == "Choice2" then 
    	if not MarketPlaceService:UserOwnsGamePassAsync(7699022) then
			MarketPlaceService:PromptProductPurchase(player, 7699022)
		elseif choice==script.Parent.Choice2 and UserStorageService(7699022) and (player.Backpack:findfirstchild("MP7A1")==nil) then
			local mp7 = game.ServerStorage["MP7A1"]:clone()
			mp7.Parent = player.Backpack
		end

	elseif choice.Name == "Choice3" then 
	    if not MarketPlaceService:UserOwnsGamePassAsync(7539220) then
			MarketPlaceService:PromptProductPurchase(player, 7539220)
		elseif choice==script.Parent.Choice3 and UserStorageService(7539220) and (player.Backpack:findfirstchild("c4")==nil) then
			local c4 = game.ServerStorage["C4"]:clone()
			c4.Parent = player.Backpack
		end
	end
end)

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gamepass, Bought)
	if Bought and plr then
		if gamepass == (7539222) then
			if UserStorageService(7539222) and (plr.Backpack:findfirstchild("M9")==nil) then
	        	local m9 = game.ServerStorage["M9"]:clone()
	        	m9.Parent = plr.Backpack
			end
		elseif gamepass == (7699022) then
			if UserStorageService(7699022) and (plr.Backpack:findfirstchild("MP7A1")==nil) then
	        	local mp7 = game.ServerStorage["MP7A1"]:clone()
	        	mp7.Parent = plr.Backpack
			end
		elseif gamepass == (7539220) then
			if UserStorageService(7539220) and (plr.Backpack:findfirstchild("C4")==nil) then
	        	local c4 = game.ServerStorage["C4"]:clone()
	        	c4.Parent = plr.Backpack
			end
		end
	end
end)

Ingame Example:
https://gyazo.com/dd9bee219bac5ff89e73525295bd62a1

You are using promptproduct purchase you should be prompting gamepass purchase(I overlooked it initially)

MarketplaceService.PromptGamePassPurchase
2 Likes

Don’t I prompt gamepass purchase here?

if not MarketPlaceService:UserOwnsGamePassAsync(7539220) then
    MarketPlaceService:PromptProductPurchase(player, 7539220)

—hold on I see my mistake in the “promptproduct” bit

1 Like

You are prompting product purchase

You forgot to add the UserId argument to UserOwnsPassAsync! And, you should use PromptGamepassPurchase.

local MarketPlaceService = game:GetService("MarketplaceService")

script.Parent.DialogChoiceSelected:Connect(function(player, choice)
	if choice.Name == "Choice1" then
		if not MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7539222) then
			MarketPlaceService:PromptGamePassPurchase(player, 7539222)
		elseif MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7539222)  and not player.Backpack:FindFirstChild("M9") then
			local m9 = game.ServerStorage["M9"]:clone()
			m9.Parent = player.Backpack
		end

	elseif choice.Name == "Choice2" then 
    	if not MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7699022) then
			MarketPlaceService:PromptGamePassPurchase(player, 7699022)
		elseif MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7539222)  and not player.Backpack:FindFirstChild("MP7A1") then
			local mp7 = game.ServerStorage["MP7A1"]:clone()
			mp7.Parent = player.Backpack
		end

	elseif choice.Name == "Choice3" then 
	    if not MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 7539220) then
			MarketPlaceService:PromptGamePassPurchase(player, 7539220)
		elseif MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7539222)  and not player.Backpack:FindFirstChild("C4") then
			local c4 = game.ServerStorage["C4"]:clone()
			c4.Parent = player.Backpack
		end
	end
end)

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gamepass, Bought)
	if Bought and plr then
		if gamepass == 7539222 then
			if not plr.Backpack:FindFirstChild("M9") then
	        	local m9 = game.ServerStorage["M9"]:clone()
	        	m9.Parent = plr.Backpack
			end
		elseif gamepass == 7699022 then
			if not plr.Backpack:FindFirstChild("MP7A1") then
	        	local mp7 = game.ServerStorage["MP7A1"]:clone()
	        	mp7.Parent = plr.Backpack
			end
		elseif gamepass == 7539220 then
			if not plr.Backpack:FindFirstChild("C4") then
	        	local c4 = game.ServerStorage["C4"]:clone()
	        	c4.Parent = plr.Backpack
			end
		end
	end
end)
2 Likes

Another thing I’ve noticed with dialogs, is that the events don’t fire for some reason. On the wiki It says it’s a client only thing, but even on the client the events don’t fire.

Try printing to see if the event is in fact working.

It’s not firing. I put a print statement just after the user has chosen an option. Nothing happens.

Are there any errors on the output? Try opting choice 1 and see if it works.

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice.Name == "Choice1" then
		print("choice 1")

https://gyazo.com/71603b66764418d8a8e3083699f7584b

1 Like

Wait ok hold on, can you try printing choice.Name?

I’m just printing after the user has selected an option.

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

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice.Name == "Choice1" then
		print("choice 1")
		if not MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7539222) then
			MarketPlaceService:PromptGamePassPurchase(player, 7539222)
		elseif choice==script.Parent.Choice1 and MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7699022) then
			local m9 = game.ServerStorage["M9"]:clone()
			m9.Parent = player.Backpack
		end

	elseif choice.Name == "Choice2" then
		print("choice 2")
    	if not MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7699022) then
			MarketPlaceService:PromptGamePassPurchase(player, 7699022)
		elseif choice==script.Parent.Choice2 and MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7699022) then
			local mp7 = game.ServerStorage["MP7A1"]:clone()
			mp7.Parent = player.Backpack
		end

	elseif choice.Name == "Choice3" then 
		print("choice 3")
	    if not MarketPlaceService:PromptGamePassPurchase(player.UserId, 7539220) then
			MarketPlaceService:PromptProductPurchase(player, 7539220)
		elseif choice==script.Parent.Choice3 and MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 7699022) and (player.Backpack:findfirstchild("c4")==nil) then
			local c4 = game.ServerStorage["C4"]:clone()
			c4.Parent = player.Backpack
		end
	end
end)

–ok i’ll try now

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice.Name == "Choice1" then
		print(choice.Name)

https://gyazo.com/1fe8f353de678434545fe87d580523c7

Try printing outside of the if statement.

If that doesn’t work, try it on the client.

I meant print it before the if statement. So like that:

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice.Name == "Choice1" then
		print(choice.Name)

By the way, this is a local script, right?

No, she’s cloning stuff from the server storage. It’s a server script. That’s why it’s not working.

1 Like

Oh dang, why are we still trying to do it if you already know it’s a server script?