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?
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?
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.
you can do it with the client sided way too if you want to make an array of people
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
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.
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!)