I know that there are still many bugs in this script, but the main problem is that the collision groups I coded isnt working. Here's what's supposed to happen:
When the player steps into the lobby queue, a border will spawn around it, preventing the player from leaving the queue. However, this restriction only applies to the player, allowing others to enter as well. But it just isn't worki8ng for some reason (code below)
#Help with my collision groups
1 messages · Page 1 of 1 (latest)
local Players_In_Area = 0
local plrs = {}
local border = script.Parent.Parent.border
local plrCounter = script.Parent.BillboardGui.TextLabel
local exitEvent = game.ReplicatedStorage:FindFirstChild("exitLobbyEvent")
PhysicsService:RegisterCollisionGroup("player")
PhysicsService:RegisterCollisionGroup("barrer")
PhysicsService:CollisionGroupSetCollidable("player", "barrer", false)
border.CollisionGroup = "barrer"
script.Parent.Touched:Connect(function(hit)
local char = hit:FindFirstAncestorWhichIsA("Model")
hit.CollisionGroup = "player"
if not plrs[char.Name] then
if game.Players:FindFirstChild(char.Name) then
plrs[char.Name] = 0
Players_In_Area += 1
for _, part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "player"
PhysicsService:CollisionGroupSetCollidable("player", "barrer", true)
end
end
local player = game.Players:GetPlayerFromCharacter(char)
local exitButton = player.PlayerGui.ExitGUI.TextButton
exitButton.Visible = true
exitEvent.OnServerEvent:Connect(function(plr)
exitButton.Visible = false
PhysicsService:CollisionGroupSetCollidable("player", "barrer", true)
Players_In_Area = Players_In_Area - 1
end)
end
end
end)
if Players_In_Area == 2 then
print("2 plrs in lobby")
end
while true do
print(Players_In_Area)
plrCounter.Text = (Players_In_Area .. "/2")
task.wait(1)
end```
Any help will be appreciated
yeah i can help
i'll send u the fixed script
local PhysicsService = game:GetService("PhysicsService")
local Players_In_Area = 0
local plrs = {}
local border = script.Parent.Parent.border
local plrCounter = script.Parent.BillboardGui.TextLabel
local exitEvent = game.ReplicatedStorage:FindFirstChild("exitLobbyEvent")
PhysicsService:RegisterCollisionGroup("player")
PhysicsService:RegisterCollisionGroup("barrier")
border.CollisionGroup = "barrier"
script.Parent.Touched:Connect(function(hit)
local char = hit:FindFirstAncestorWhichIsA("Model")
if not char then return end
local humanoid = char:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local player = game.Players:GetPlayerFromCharacter(char)
if not player then return end
if not plrs[player.UserId] then
plrs[player.UserId] = true
Players_In_Area += 1
for _, part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "player"
end
end
PhysicsService:CollisionGroupSetCollidable("player", "barrier", true)
local exitButton = player.PlayerGui.ExitGUI.TextButton
exitButton.Visible = true
end
end)
exitEvent.OnServerEvent:Connect(function(plr)
if plrs[plr.UserId] then
plrs[plr.UserId] = nil
Players_In_Area -= 1
local char = plr.Character
if char then
for _, part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "Default"
end
end
end
plr.PlayerGui.ExitGUI.TextButton.Visible = false
if Players_In_Area == 0 then
PhysicsService:CollisionGroupSetCollidable("player", "barrier", false)
end
end
end)
while true do
plrCounter.Text = (Players_In_Area .. "/2")
if Players_In_Area == 2 then
print("2 plrs in lobby")
end
task.wait(1)
end
tell me if it works
@obsidian delta
alr