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

How would I make a proper VIP only door script? (Code Included)

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)

2 comments

0

why don't you from a localscript do if game.Players.LocalPlayer.Name == "name" then workspace.Part.CanCollide = false end

0

because they have to own a gamepass to enter the room with the VIP door

1 answer

✓ Accepted answer

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.

4 comments

0

You mean the use of region3 right?

0

You could use a region3, but that's not how I do it because they are axis-aligned and FindPartsInRegion3 is overkill. I just define the area in Workspace with a semi-transparent block. The server consumes the block on startup, keeping CFrame and Size. On heartbeat, once a second, I check the players using the vector from the block position to their HRP position, projected onto the block CFrame's a

0

If the projections are all shorter than half the part's size on each respective axis, the point is inside the region the block defined.

0

There are a lot of optimizations you can do to make the cost negligible. Only loop over an array of just the non-VIP players. Check one player per Heartbeat. Store the square of half the length of the region's longest diagonal, so it's just one dot product to know if someone's definitely outside the box. Early out on the projection checks as soon as one fails. Etc.

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