I’m new to scripting and I know this script is very easy and simple but I’m having a problem.
The script functions as it should, but if someone isn’t in the group and walks right behind the player in the group, that person can enter the door. I was wondering how to make it local or client-sided so this doesn’t happen.
local groupID = 32857623 -- The group ID the player must be in
local groupMembers = {} -- Table to store group member states
script.Parent.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if player:IsInGroup(groupID) then
groupMembers[player.UserId] = true
script.Parent.CanCollide = false
else
groupMembers[player.UserId] = false
script.Parent.CanCollide = true
end
end
end)
-- Update collision state when player leaves
game.Players.PlayerRemoving:Connect(function(player)
groupMembers[player.UserId] = nil
end)
-- Continuous collision state check
while true do
for userId, inGroup in pairs(groupMembers) do
local player = game.Players:GetPlayerByUserId(userId)
if player and inGroup then
script.Parent.CanCollide = false
break
end
end
wait(1)
end