Created
May 30, 2025 15:58
-
-
Save MajorTal/c3d8f104a24a3ffbad65fa8b356c5dac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local Players = game:GetService("Players") | |
| local rooms = workspace.PlayerRooms:GetChildren() | |
| local roomAssignments = {} | |
| -- 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 | |
| roomAssignments[player.UserId] = room.Name | |
| player:SetAttribute("Room", room.Name) | |
| 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 | |
| end | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment