Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
1
Answered by
G2001H 75
5 years ago
Edited 5 years ago
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)
1
^^ GetService should also be used the "Players" and you're missing the (hit) variable in the connection SerpentineKing 3885 — 5y
0
SerpentineKing Im not missing nothing, Try the Script in game not in Studio, it work perfect. G2001H 75 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

Answer this question