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 8 years ago
Edited 8 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':

01local passId = 622740681
02local marketplaceService = game:GetService("MarketplaceService")
03 
04function onTouched(hit)
05    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
06    if player then
07        marketplaceService.PromptPurchaseFinished:connect(function(player,assetId,isPurchased)
08            if isPurchased then
09                if assetId == passId then
10                    game.GetService("TeleportService"):Teleport(623097807, player)
11                end
12            end
13        end)
14    end
15end
16script.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 — 8y
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 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Found a solution!

01local passId = 000000000 -- change this to the game pass ID.
02 
03function authenticate(player)
04    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
05end
06 
07script.Parent.Touched:connect(function(hit)
08    if game.Players:FindFirstChild(hit.Parent.Name) then
09        if authenticate(game.Players[hit.Parent.Name]) then
10            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
11            game:GetService("TeleportService"):Teleport(00000000, player) -- Change the 0s to your 'other game' id
12        end
13    end
14end)
Ad

Answer this question