Advertisement
Marcel12311

Roblox check how many players scripts

Jan 20th, 2022
1,084
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ Roblox check how many players are on the server
  2. INSTRUCTION:
  3. --
  4. 1.First Create ScreenGui and inside ScreenGui create Frame and inside Frame create TextLabel and can u edit property for your needs...
  5. 2.inside (TextLabel) create Local Script and edit it.. put this script called LOCAL SCRIPT
  6. 3.inside ServerScriptService create script and put scripts called SCRIPT (just edit the script)
  7. 4.ReplicatedStorage create RemoteEvent and dont change name..
  8. 5.Run Game!
  9. 6.Finish...
  10. --
  11.  
  12. if you have problem with understanding... I posted a video here:
  13. https://www.youtube.com/watch?v=1HY4aTTheaA
  14.  
  15. Enjoy guys!
  16. ]]--
  17. ---------------------------------------------------------------------
  18. ---------------------------------------------------------------------
  19. --LOCAL SCRIPT
  20. local textLabel = script.Parent
  21. local remoteEvent = game.ReplicatedStorage.RemoteEvent
  22.  
  23. local function onEvent(numbers)
  24.     textLabel.Text = "Players: ".."("..numbers.."/"..game.Players.MaxPlayers..")"
  25. end
  26.  
  27. remoteEvent.OnClientEvent:Connect(onEvent)
  28. ---------------------------------------------------------------------
  29. ---------------------------------------------------------------------
  30. --SCRIPT
  31. local remoteEvent = game.ReplicatedStorage.RemoteEvent
  32. -- variable stores the number of players on the server
  33. local PlayersOnServer = 0
  34.  
  35.  
  36.  
  37. local function onJoin(plr)
  38.     if plr then
  39.         PlayersOnServer+=1
  40.         remoteEvent:FireAllClients(PlayersOnServer)
  41.     end
  42. end
  43.  
  44. local function onLeft(plr)
  45.     if plr then
  46.         PlayersOnServer-=1
  47.         remoteEvent:FireAllClients(PlayersOnServer)
  48.     end
  49. end
  50.  
  51. game.Players.PlayerAdded:Connect(onJoin)
  52. game.Players.PlayerRemoving:Connect(onLeft)
  53. ---------------------------------------------------------------------
  54. ---------------------------------------------------------------------
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement