Answered by
4 years ago Edited 4 years ago
Hello, JasiuJasiuB!
For ... do loop
a for ... do
loop increments a value until it reaches an objective:
prints:
for ... do
loops can be also used with tables:
1 | local table = { "value1" , "value2" , "value3" , "value4" , "value5" } |
3 | for i,v in pairs (table) do |
this results in:
It is exactaly the same as doing
1 | local table = { "value1" , "value2" , "value3" , "value4" , "value5" } |
This makes your code lots smaller, as you can see
game:GetService()
game:GetService()
is used to get internal services of roblox, like the UserInputService
or MessagingService
There're some special services, that you can see on the studio, such as Players
, ReplicatedStorage
, ServerStorage
, and many others.
I'll explain just what you want, as I don't want this to be too long:
game:GetService("Players"):GetPlayers()
-- this will return a table containing all the players objects on the game, so we can use a for ... do
loop to cycle it:
1 | local playersList = game:GetService( "Players" ):GetPlayers() |
2 | for i,v in pairs (playersList) do |
Useful links:
https://developer.roblox.com/en-us/api-reference/function/ServiceProvider/GetService
https://www.lua.org/pil/4.3.4.html
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers
Hope this helps!