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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
why don't you from a localscript do if game.Players.LocalPlayer.Name == "name" then workspace.Part.CanCollide = false end greatneil80 2647 — 4y
0
because they have to own a gamepass to enter the room with the VIP door Tyler090130 619 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
You mean the use of region3 right? XviperIink 428 — 4y
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 EmilyBendsSpace 1025 — 4y
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. EmilyBendsSpace 1025 — 4y
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. EmilyBendsSpace 1025 — 4y
Ad

Answer this question