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

Is there a way to make a proper gamepass-only door?

Asked by
7z99 203 Moderation Voter
5 years ago

Hello!

I have a gamepass-only door that disables collision for about half a second, but the issue with this is that while the collision is on, anyone can pass through, even if they don't have the gamepass. Can I use collision groups for this?

1
While the door is open, if someone touch it check if they have the gamepass. If not, you can teleport them back or kill them. JakyeRU 637 — 5y
1
This is not a request site. However, there are probably a billion videos about this on youtube so I suggest you look there, make a script, and come back if you're still having problems (BRING A SCRIPT NEXT TIME!) MustangHeart 67 — 5y

2 answers

Log in to vote
0
Answered by
Optikk 499 Donator Moderation Voter
5 years ago

A server sided approach is to use PhysicsService and collision groups. Here is an example:

local PhysicsService = game:GetService('PhysicsService')

-- create 2 groups (one for the player's parts and one for the gamepass door)
local playerGroup = PhysicsService:CreateCollisionGroup('PlayerGroup')
local wallGroup = PhysicsService:CreateCollisionGroup('DoorGroup')

-- now any parts in the PlayerGroup or DoorGroup collision groups will not collide with one another, allowing the parts to pass through eachother
PhysicsService:CollisionGroupSetCollidable('PlayerGroup', 'DoorGroup', false)

-- you'll want to set the collision group of your gamepass door, whatever you named it, to DoorGroup
PhysicsService:SetPartCollisionGroup(workspace.GamepassDoor, 'DoorGroup')

With this code, you can manage who can walk through a brick or not. If you set the collision group of any part to 'PlayerGroup', they will no longer experience collision with 'workspace.GamepassDoor'

You then just check if the player has the gamepass and set the collision group of all of their parts to 'PlayerGroup':

local MarketplaceService = game:GetService('MarketplaceService')

if MarketplaceService:UserOwnsGamePassAsync(userId, gamepass) then
    -- here i'm filtering through the character's parts to add any basepart to the PlayerGroup collision group
    for _, part in pairs(character:GetChildren()) do
        if part:IsA('BasePart') then
            -- keep in mind you'll have to do this every time the player respawns!
            PhysicsService:SetPartCollisionGroup(part, 'PlayerGroup')
        end
    end
end

I hope this helps! Let me know if you have any questions.

0
you can do it with the client sided way too if you want to make an array of people srimmbow 241 — 5y
Ad
Log in to vote
0
Answered by
srimmbow 241 Moderation Voter
5 years ago
Edited 5 years ago

A really good way to do this is actually to use Local Scripts to make it non-collidable for someone if they own a gamepass! Just run a Local Script that checks if they own and if they do, make the part non collidable. Since it's in a Local Script, it's only non collidable for people with the gamepass. There's no chance of any other people getting in.

Answer this question