Im trying to use a collision groups script, but it doesn't seem to be working. I added some prints, and they work fine, but the player is not able to go through door. Any help? Server script inside wall:

local Players = game:GetService('Players')
local PhysicsService = game:GetService('PhysicsService')

local AccessList = {}

local Door = script.Parent
local RequiredTokens = 750

PhysicsService:CreateCollisionGroup(Door, "doorGroup") -- set the Door's group

function TOUCHED(hit)
    if hit then 
        if Players:FindFirstChild(hit.Parent.Name) then 
        local player = Players:FindFirstChild(hit.Parent.Name)
        local Tokens = player:FindFirstChild("leaderstats").Coins
        if not CHECK_LIST(player.Name) and (Tokens.Value >= 10) then 
	
print("accepted")
            local character = player.Character
            ACCESS(character)
        end
end
    end
end

function ACCESS(character)
    if character then 
        for _, v in pairs(character:GetChildren()) do 
            if v:IsA('BasePart') then 
	print("added")
                PhysicsService:SetPartCollisionGroup(v, "accessGroup")
                table.insert(AccessList, character.Name) -- add player to access group
            end
        end
    end
end

function CHECK_LIST(playerName) -- checks if the player is in the access list/not
    for i = 1, #AccessList do 
        if (playerName == AccessList[i]) then 
            return true 
        else
            return false 
        end
    end
end

Door.Touched:connect(TOUCHED)

Server script in serverscriptservice:

local PhysicsService = game:GetService("PhysicsService")

local doorGroup = "doorGroup"
local accessGroup = "accessGroup"

--you can only create a collision group once. If it already exists it will return a error

PhysicsService:CreateCollisionGroup(doorGroup)
PhysicsService:CreateCollisionGroup(accessGroup)
while wait(1) do

PhysicsService:CollisionGroupSetCollidable(doorGroup, accessGroup, false) -- makes the two groups uncollidable with eachother
end

2 comments

0

Dont use while wait() do. And I don't know why (Tokens.Value >= 10) is in parentheses? >= has higher precedence than and.

0

on line 12 hit is undefined