Skip to content

Instantly share code, notes, and snippets.

@MajorTal
Created May 30, 2025 16:20
Show Gist options
  • Select an option

  • Save MajorTal/c83b9dbc59bf858edaa7e97ddcb3218e to your computer and use it in GitHub Desktop.

Select an option

Save MajorTal/c83b9dbc59bf858edaa7e97ddcb3218e to your computer and use it in GitHub Desktop.
local Players = game:GetService("Players")
local rooms = workspace.PlayerRooms:GetChildren()
local roomAssignments = {}
local signsFolder = workspace.Signs
-- Shuffle rooms for randomness (optional)
local function shuffle(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
end
shuffle(rooms)
Players.PlayerAdded:Connect(function(player)
local room = table.remove(rooms, 1)
if not room then
warn("No available rooms left!")
return
end
-- Assign room to player
roomAssignments[player.UserId] = room.Name
player:SetAttribute("Room", room.Name)
-- Update Sign with player's name
local roomNumber = room.Name:match("%d+$") -- extracts the number from "Room1"
local sign = signsFolder:FindFirstChild("Sign" .. roomNumber)
if sign then
local textLabel = sign:FindFirstChild("Text"):FindFirstChild("SurfaceGui"):FindFirstChild("TextLabel")
if textLabel then
textLabel.Text = player.Name
else
warn("TextLabel not found in Sign" .. roomNumber)
end
else
warn("Sign not found for Room" .. roomNumber)
end
player.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local spawnPoint = room:FindFirstChild("Spawn")
if spawnPoint then
hrp.CFrame = spawnPoint.CFrame + Vector3.new(0, 3, 0)
else
hrp.CFrame = room:GetPivot() + Vector3.new(0, 5, 0)
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
local roomName = roomAssignments[player.UserId]
if roomName then
table.insert(rooms, workspace.PlayerRooms[roomName])
roomAssignments[player.UserId] = nil
-- Clear the sign when player leaves
local roomNumber = roomName:match("%d+$")
local sign = signsFolder:FindFirstChild("Sign" .. roomNumber)
if sign then
local textLabel = sign:FindFirstChild("Text"):FindFirstChild("SurfaceGui"):FindFirstChild("TextLabel")
if textLabel then
textLabel.Text = "Waiting..."
end
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment