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.

01local TeleportService = game:GetService("TeleportService")
02 
03local placeID_1 = 0000000000
04 
05local function onPartTouch(otherPart)
06    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
07    if player then
08        TeleportService:Teleport(placeID_1, player)
09    end
10end
11script.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
01local TeleportService = game:GetService("TeleportService")
02local MPS = game:GetService("MarketplaceService")
03local gamepass = 0000000
04local placeID_1 = 0000000000
05 
06local function onPartTouch(hit)
07    local hum = hit.Parent:FindFirstChild("Humanoid")
08        if hum then
09        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
10            if MPS:UserOwnsGamePassAsync(player.UserId,gamepass) == true then
11            TeleportService:Teleport(placeID_1, player)
12        end
13    end
14end
15script.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.

01local ID = 000000000
02local Game = 00000000000
03 
04game.Players.PlayerAdded:Connect(function(p)
05  local function touch(hit)
06  if game:GetService("MarketplaceService"):PlayerOwnsGamePassAsync(p.UserId, ID) then
07   game:GetService("TeleportService"):Teleport(Game, p)
08  else game:GetService("MarketplaceService"):PromptGamePassPurchase(p, ID)
09  end
10  end
11  workspace.Part.Touched:Connect(touch)
12end)

Answer this question