When I try to check if a local is less than another local in a spawn(function(), I simply get an error. Here is the script code I am using:
local remotewin = ReplicatedStorage:WaitForChild("Remotewin")
local ingame = {}
local clasifmin = 0
local plrwinsnumber = 0
for i,player in pairs(game.Players:GetPlayers()) do
table.insert(ingame, player)
end
clasifmin = math.round(#ingame*50 / 100)
spawn(function() -- start new thread
for i,player in pairs(game.Players:GetPlayers()) do
local function onCreatePart()
if plrwinsnumber <= clasifmin then
plrwinsnumber += 1
end
remotewin.OnServerEvent:Connect(onCreatePart)
end
end
end)
while wait() do
print ((plrwinsnumber).. "/" .. (clasifmin))
end
Updated code, not sure why you’d want a new thread for that, but here’s the updated version…
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotewin = ReplicatedStorage:WaitForChild("Remotewin")
local ingame = {}
local clasifmin = 0
local plrwinsnumber = 0
clasifmin = math.round(#Players:GetPlayers()*50 / 100)
coroutine.wrap(function()
while wait() do
print ((plrwinsnumber).. "/" .. (clasifmin))
end
end)()
Players.PlayerAdded:Connect(function(Player)
clasifmin = math.round(#Players:GetPlayers()*50 / 100)
local function onCreatePart()
if plrwinsnumber <= clasifmin then
plrwinsnumber += 1
end
end
remotewin.OnServerEvent:Connect(function()
onCreatePart()
end)
end)
If this doesn’t function the way you wish, feel free to reply.
I want to make that, for example, if in a game there are 4 players, the script prints 0/2((plrwinsnumber)… “/” ..(classifmin)) because it is 50% of the number of players. And, for each player that activates the remote event, add +1 to the local plrwinsnumber. And so, when the script checks that (plrwinsnumber) == (clasifmin) it will stop printing. And the last thing the server has to print is 2/2
In that case, try this. Make sure it is a server script in ServerScriptService.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotewin = ReplicatedStorage:WaitForChild("Remotewin")
local ingame = {}
local clasifmin = 0
local plrwinsnumber = 0
local function onCreatePart()
if plrwinsnumber <= clasifmin then
plrwinsnumber += 1
end
end
coroutine.wrap(function()
while task.wait() do
if plrwinsnumber == clasifmin then
break
end
print ((plrwinsnumber).. "/" .. (clasifmin))
end
end)()
remotewin.OnServerEvent:Connect(function(Player)
onCreatePart()
end)
Players.PlayerAdded:Connect(function(Player)
clasifmin = math.round(#Players:GetPlayers() / 2)
end)