Gamepass Button Help

You can write your topic however you want, but you need to answer these questions:

  1. Hello! I am trying to make a button that only activates if a player owns a gamepass, it activates from a click detector.

  2. I want to make it so that if the player clicks it but doesn’t own the gamepass that it prompts the player the gamepass and kills the player but I don’t know how to yet,

  3. I have looked through the DevForum beforehand and found gamepass buttons but none kill the player if they don’t own the gamepass.

The button if the gamepass is owned will activate a self-destruct mode inside my game which I have already accomplished.

SCRIPT


local MPS = game:GetService("MarketplaceService")
local gamepassId = 45131258
local function promptPurchase(Player)
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MPS:UserOwnsGamePassAsync(Player.UserId, gamepassId)
	end)
	if hasPass == true then
		workspace.SelfDestruct.Disabled = false
		script.Disabled = true
	else
		
		-- stuck here with killing player
		MPS:PromptGamePassPurchase(Player, gamepassId)
	end
end
script.Parent.ClickDetector.MouseClick:Connect(promptPurchase)

Please let me know if you can help!

1 Like

Do you want kill everyone in server?

only the player who activated it

Well where you are stuck with killing the player…

Depending on this is a Server Script or Local Script. It seems to be server script, on a part if im right? If so…

You should just be able to add this in →

Player.Character.Humanoid.Health = 0

You may want to add another variable like →

local char = Player:WaitForChild("Character")
char.Humanoid.Health = 0

Either of these should work.

Try this script:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local hasPass = false
	local s, e = pcall(function()
		hasPass = MPS:UserOwnsGamePassAsync(player.UserId, gamepassId)
	end)
	if not s then
		warn(e)
	end
	if s and hasPass then
		game.Workspace.SelfDestruct.Disabled = false
		script.Disabled = true
	else
		player.Character:FindFirstChild("Humanoid").Health = 0
		MPS:PromptGamePassPurchase(player.UserId, gamepassId)
	end
end)

I do not recommend killing the player when the player have not buy it thou…