Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a script only work if the player owns a gamepass?

So I have a script, but I want it to only work if the player owns a game pass.

local TeleportService = game:GetService("TeleportService")
 
local placeID_1 = 0000000000
 
local function onPartTouch(otherPart)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
		TeleportService:Teleport(placeID_1, player)
	end
end
script.Parent.Touched:Connect(onPartTouch)

Anybody know how to do this?

2 answers

✓ Accepted answer
local TeleportService = game:GetService("TeleportService")
local MPS = game:GetService("MarketplaceService")
local gamepass = 0000000
local placeID_1 = 0000000000

local function onPartTouch(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if MPS:UserOwnsGamePassAsync(player.UserId,gamepass) == true then
        	TeleportService:Teleport(placeID_1, player)
		end
    end
end
script.Parent.Touched:Connect(onPartTouch)

2 comments

1

^^ GetService should also be used the "Players" and you're missing the (hit) variable in the connection

0

SerpentineKing Im not missing nothing, Try the Script in game not in Studio, it work perfect.

pls accept, i have used this concept before.

local ID = 000000000
local Game = 00000000000

game.Players.PlayerAdded:Connect(function(p)
  local function touch(hit)
  if game:GetService("MarketplaceService"):PlayerOwnsGamePassAsync(p.UserId, ID) then
   game:GetService("TeleportService"):Teleport(Game, p)
  else game:GetService("MarketplaceService"):PromptGamePassPurchase(p, ID)
  end
  end
  workspace.Part.Touched:Connect(touch)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.