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