Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local playerService = game:GetService("Players")
- local bindableFunction = game.ReplicatedStorage.GetPlayers
- local players = {}
- -- used for debugging tools
- local function listPlayers()
- for i, player in pairs(players) do
- print(player)
- end
- end
- -- adds player to the player list
- playerService.PlayerAdded:Connect(function(player)
- local playerTableListLength = #players
- local newPlayerPosition = playerTableListLength + 1
- players[newPlayerPosition] = player.Name
- end)
- -- removes player from the player list
- playerService.PlayerRemoving:Connect(function(player)
- local playerName = player.Name
- local leavingPlayerPosition = -1
- -- updating list
- local playerListBuffer = {}
- local currentIndex = 1
- for i, player in pairs(players) do
- if player == playerName then
- continue
- end
- playerListBuffer[currentIndex] = player
- currentIndex += 1
- end
- -- assigning buffer to the player list
- players = playerListBuffer
- end)
- local function getPlayerList()
- return players
- end
- bindableFunction.OnInvoke = function()
- return getPlayerList()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement