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

Teleport to different place on brick touch and has gamepass?

Asked by 7 years ago
Edited 7 years ago

In my game, I am trying to make a 'VIP Door' which will need the player to buy a gamepass so they can teleport to another place. I have put the place in 'Other Places' on the roblox website and put the following code in a script inside the 'Door':

local passId = 622740681 
local marketplaceService = game:GetService("MarketplaceService")

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        marketplaceService.PromptPurchaseFinished:connect(function(player,assetId,isPurchased)
            if isPurchased then 
                if assetId == passId then 
                    game.GetService("TeleportService"):Teleport(623097807, player)
                end
            end
        end)
    end
end
script.Parent.Touched:connect(onTouched)

If you can see, I used some help from the roblox wiki, but I can't get it to work.

0
Any errors? If not, put a print("line works") between each line and see where it stops, then I may find the problem. awfulszn 394 — 7y
0
It stops at line 6 (last line where it works). The gamepass isn't on for sale yet. Should put it up for sale? Moshipikachu123456 15 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

Found a solution!

local passId = 000000000 -- change this to the game pass ID.

function authenticate(player)
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

script.Parent.Touched:connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        if authenticate(game.Players[hit.Parent.Name]) then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            game:GetService("TeleportService"):Teleport(00000000, player) -- Change the 0s to your 'other game' id
        end
    end
end)
Ad

Answer this question