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

Why doesn't this Gamepass script work?

Asked by 8 years ago
local passId = 396490188

function isAuthenticated(player) 
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        print(plr.Name .. " has bought the game pass with id " .. passId)
    end

function ontouch() 
    game:GetService("TeleportService").CustomizedTeleportUI = true
local teleportService = game:GetService("TeleportService")
local otherPlaceId = 215389447
local button = script.Parent
local loadingScreen = script.Parent.Parent
local player = game.Players.LocalPlayer

 button.MouseButton1Down:connect(function()
    game:GetService("TeleportService"):Teleport(otherPlaceId, player)
    loadingScreen.Visible = true
    for i = 1, 0, -.05 do
        loadingScreen.BackgroundTransparency = i
        wait()
    end
    loadingScreen.BackgroundTransparency = 0

Thanks for answering! The goal of the script is to see if you have the game pass and if you do teleport you to another part of the universe. I tested the script out ingame and when I touched the part that was suppose to do that It wasn't doing it and I can't spot anything wrong with this script so I came to you guys for help, again thanks! :)

1 answer

Log in to vote
0
Answered by 8 years ago

You were missing a lot.

The below script should teleport the player when they touch a brick and if they have the gamepass.

-- script in part in workspace
local passId = 396490188
local teleportService = game:GetService("TeleportService")
local otherPlaceId = 215389447
--^ variables


function isAuthenticated(player) --gets activated later
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)--checks for player gamepass
end

script.Parent.Touched:connect(function(part) -- tocuhed event
    if not part.Parent:FindFirstChild("Humanoid") then return end
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)-- get player
    if not plr then return end

    if isAuthenticated(plr) then--check gamepass
        game:GetService("TeleportService").CustomizedTeleportUI = true
        teleportService:Teleport(otherPlaceId, plr)--teleport
    end
end)
The above script will teleport the player if they have the gamepass.

Here's some links to help in the future,

Teleport Service Guide

gamepass service

I hope I helped!

Good Luck!

Ad

Answer this question