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

Block that lets only players with a gamepass through?

Asked by
ghaybe 5
6 years ago

Hello, I've recently been trying to script something where I'm creating an area only players with a certain gamepass can access. Looking through some of my old creations, I found a functioning script that only works under the old system of gamepasses having normal IDs. If the player does not have the gamepass, it will teleport them a few blocks back. Could anyone help? Much appreciated, Gabe.

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
6 years ago
Edited 6 years ago

It's because of the recent GP change that requires MarketplaceService now. Try putting this script in a part/door. Take out the bottom portion if you don't want the door to kill non-gamepass holding players. You can add your teleport part of the script there if you like.

local door = script.Parent

function open()
    door.CanCollide = false
end

function close()
    door.CanCollide = true
end

function get_player(part)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if part:IsDescendantOf(player.Character) then
            return player
        end
    end
end

door.Touched:Connect(function(part)
    local player = get_player(part)
    local character = player.Character
    if not player then return end

    local allow = (
        game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.userId, 1234567) -- Paste your game pass id here
    )

    if allow then
        open()
        delay(4, close)
    else
        character.Humanoid.Health = 0
    end
end)
0
You know you don't need a separate function just to toggle a boolean? Using the 'not' keyword can do this for you. User#19524 175 — 6y
0
Also the allow variable doesn't need to be formatted like that you can just have it in one line. User#19524 175 — 6y
0
Thank you very much! It worked flawlessly. I appreciate your help! ghaybe 5 — 6y
0
No problem...Ok, thank you incapaz. ABK2017 406 — 6y
Ad

Answer this question