Answered by
6 years ago Edited 6 years ago
To get your main question out of the way:
You're trying to using tonumber()
on a table. This won't return a number since you're using it on a table. To get the length of a table you use the '#' operator before table returning the length of it. You use tonumber()
to convert another data type to a number type.
1 | local Players = game.Players:GetPlayers() |
2 | local PlayerAmount = #Players |
Now you have a lot of things in your code that you shouldn't do. One of those things is how you're defining services and using WaitForChild()
. You should only use WaitForChild()
when getting things like objects inside of services (I usually use it in client side of things)
When getting a service use the :GetService()
method.
1 | local RepStorage = game:GetService( "ReplicatedStorage" ) |
2 | local Players = game:GetService( "Players" ) |
5 | local Remote = RepStorage:WaitForChild( "GameRemote" ) |
Second, you should use functions to run code that you know you'll be using later.
03 | local function CheckPlayerCount() |
04 | local Players = game.Players:GetPlayers() |
05 | local PlayerAmount = #Players |
11 | local playersActive = CheckPlayerCount() |
13 | if playersActive > 2 then |
14 | Remote:FireAllClients() |
edit: fixed the rest of your code