'Why this code doesn't works in roblox studio?? I'm new and I don't know why it gives me error
local contador = 1
local jugadores = game.Players
while jugadores > 3 do
while contador > 10 do
contador = contador + 1
print("Quedan " ..contador.. "segundos")
wait(1)
print( "Hay "..jugadores.. "jugadores" )
end
end
I gives me error in the bold words and the parentesis
I tryed to quit the parentesys but I'm new and I don't know what to do. Thanks
Solution 1:[1]
Because you are using a Script in the Workspace, it will execute as soon as it is loaded into the world. So when this code runs it will go something like this :
- there are no players in the world...
- is
jugadoresgreater than 3? no, skip the loops... - exit
So you need to have a way to wait for players to join the game before you execute your logic. I would recommend using the Players.PlayerAdded signal as a way to check when there are enough players.
local Players = game:GetService("Players")
-- when a player joins the game, check if we have enough players
Players.PlayerAdded:Connect(function(player)
local jugadoresTotal = #Players:GetPlayers()
print(string.format("Hay %d jugadores", jugadoresTotal))
if jugadoresTotal > 3 then
local contador = 1
while contador <= 10 do
print(string.format("Quedan %d segundos", contador))
wait(1)
contador = contador + 1
end
-- do something now that we have 4 players
end
end)
Solution 2:[2]
Yes - To Concat strings together use two dots not two asterisk.
So use .. instead of: **
http://www.lua.org/pil/3.4.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | koyaanisqatsi |
