Dialog choice for gamepass

Heya guys! I’m making a game but to make it some fun I need your help. If player starting dialog with NPC and using one answer he must have specific gamepass. If he don’t have it he will get killed. But how do I do that?

local Marketplace = game:GetService("MarketplaceService")

local Part = workspace:WaitForChild("Part") --Example.
local Dialog = Part:WaitForChild("Dialog") --Example.
local DialogChoice = Dialog:WaitForChild("DialogChoice") --Example.

local GamepassId = 0 --Change to ID of gamepass.

Dialog.DialogChoiceSelected:Connect(function(Player, Choice)
	if Choice == DialogChoice then
		if Marketplace:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			--Do code if player owns gamepass.
		else
			Player.Character.Humanoid.Health = 0
		end
	end
end)

Added script, trying to talk with owned gamepass, dialog is not working. In what problem? :frowning:

The script is a local script placed inside “StarterPlayerScripts”.

repro.rbxm (3.3 KB)

Here’s the model file I used to test (it works).

It’s a simple BasePart instance with a dialog option, clicking “Hello world!” will kill the kill the player’s character if they don’t own a particular gamepass.