How do I make an npc that sells gamepasses through dialog?

So like this?
indent preformatted text by 4 spaceslocal dialog = game.Workspace.Ryanthemudkip.Head.Saledialog.Dialogchoice1
local client = game:GetService(“Players”).LocalPlayer

dialog.DialogChoiceSelected:Connect(function(player, dialog)
if player ~= client then
return
end

– Services
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketplaceService = game:GetService(“MarketplaceService”)

– Setup RemoteEvent in ReplicatedStorage
local promptPurchaseEvent = Instance.new(“RemoteEvent”)
promptPurchaseEvent.Name = “PromptPurchaseEvent”
promptPurchaseEvent.Parent = ReplicatedStorage

– Listen for the RemoteEvent to fire from a Client and then trigger the purchase prompt
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
MarketplaceService:PromptPurchase(player, id)
end)
– Extra code
end)

No not necessarily. Don’t just copy paste an entire script into the function.

More like this (P.D. you don’t need a remote to prompt purchases!).

local dialog = game.Workspace.Ryanthemudkip.Head.Saledialog
local client = game:GetService("Players").LocalPlayer

local MarketplaceService = game:GetService("MarketplaceService")

dialog.DialogChoiceSelected:Connect(function(player, choice)
    if player ~= client then
        return
    end
    
    if choice.Name == "Dialogchoice1" --[[ or whatever it was]] then
        MarketplaceService:PromptGamePassPurchase(client, id) -- Whatever the ID was
    end
end)
How to post a code block

```lua
– Code here
```

Three backticks (aka grave accents then the file extension of the language. Lua is used in this case.

which becomes

-- Code here
3 Likes

Alright, I’ll try that. Thanks for the tutorial on code blocks too lmao

So, I tried it, and the dialog works but the purchase prompt doesn’t show.

Can you show us the code you used? If you add a print statement in the function, it can be used to check if the function actually worked or not.

I found the problem, I forgot to change the code after I put the npc in a model