Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Block that lets only players with a gamepass through?

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

✓ Accepted answer

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)

4 comments

0

You know you don't need a separate function just to toggle a boolean? Using the 'not' keyword can do this for you.

0

Also the allow variable doesn't need to be formatted like that you can just have it in one line.

0

Thank you very much! It worked flawlessly. I appreciate your help!

0

No problem...Ok, thank you incapaz.

This discussion is preserved as it was. New answers, comments, and votes are closed.