I am trying to make a VIP only door so only people with the VIP gamepass can enter the room. This script is supposed to turn off collision for people who have the gamepass, but it's just not working correctly. Any help?
local GamepassService = game:GetService("MarketplaceService") local PhysicsService = game:GetService("PhysicsService") local GamepassDoor = workspace:WaitForChild("VIProom_new"):WaitForChild("vp_BTAI50iN25") local GamepassId = 6574369 local Group = "Owners" PhysicsService:CreateCollisionGroup(Group) PhysicsService:CollisionGroupSetCollidable(Group, Group, false) PhysicsService:SetPartCollisionGroup(GamepassDoor, Group) game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) if GamepassService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then for _,v in pairs(Character:GetDescendants()) do if v:IsA("BasePart") then PhysicsService:SetPartCollisionGroup(v, Group) end end end end) end)
You can't just set the character parts' collision group on CharacterAdded, since at this time the player has a default blocky character, not their actual avatar appearance package parts. You need to also hook up a character.DescendantAdded
listener function so that any part which gets added to their character model afterwards also gets its collision group set appropriately. Alternately, you could loop over the character again on player.CharacterApperanceLoaded time, but I've found it slightly more reliable to do it on a per-part basis (DescendantAdded), and this will also cover the case where the game adds things to the character after they spawn (like those pads you stand on to get a hat, or whatever).
Also, a "proper" VIP area needs more than this to secure it from no-clip exploiters. You should additionally have the server periodically validate that everyone in the VIP room actually belongs there. I do this in my games on heartbeat, roughly once per second, where it checks the position of all players against the bounds of the VIP area. If someone who doesn't have the gamepass is in the area, they get OOF'd.