Group Door not working

I’m working on a group door that teleports you to the other side and I’m having some difficulty with this - I simply edited a gamepass door that we had where it teleports you to the other side - and that one works completely fine.

However this one refuses to work for me when I edited it to make it work for group ranks.

Here’s the code:

local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end



local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')

local VipDoor = script.Parent

local GamePassIdObject = script: WaitForChild('GamePassId')

local JustTouched = {}


local function TeleportToOtherSide(character, hitPart)
	local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
	local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
	local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3
	
	local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
	local distanceToBack = (behindDoor - hitPart.Position).magnitude
	if distanceToFront < distanceToBack then
		character:MoveTo(behindDoor)
	else
		character:MoveTo(inFrontOfDoor)
	end
end

local function OnTouched(otherPart)
	if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
		local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
		local config = script.Configuration
		if player and not JustTouched[player] then
			JustTouched[player] = time()
			if player:GetRankInGroup(config.GroupId.Value) >= config.RankId.Value then
				TeleportToOtherSide(player.Character, otherPart)
			end
		end
	end
end

local function RemoveOldTouches()
	for player, touchTime in pairs(JustTouched) do
		if time() > touchTime + 0.3 then
			JustTouched[player] = nil
		end
	end
end


VipDoor.Touched:connect(OnTouched)

while true do
	RemoveOldTouches()
	wait(1/30)
end
1 Like

What error do you get when you try and use this?

Oh my god the code you posted is so over-complicated. All you really can do is just:

door.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        --It is a Player
        local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if Player:IsInGroup(0000000) then
             --Open the door
        end
    end
end)

You might want to implement some sort of Debounce, but you should do that yourself. :slightly_smiling_face:

1 Like

You need to be in the same group and have the same rank or above
You can use <= to get ranks less than

And try to use some prints at most spots in the script
I know that’s a basic thing but at least it does work enough

I made a quick video showing how to do this:

You can skip to 3:09, that is when the Group Door part starts. I made a typo on line 6, this should be CanCollide, and not ConCollide.
Hope this helped!