Hello,
So I am building a round system game.
The round ends whenever the time has run out OR when all players have died.
This sounds really simple and it probably is but I can’t get it to work no matter what.
This is my current code
while playerCount.Value > 0 do
if timePassed <= TimeLimit then
--Time left is equal to itself minus the time that has passed.
local TimeLeft = TimeLimit-timePassed
--Sets the status value with the remaining time.
status.Value = "You have "..TimeLeft.." seconds left to escape!"
--Add 1 more second to the time that has passed.
timePassed = timePassed+1
wait(1)
end
end
The variable “playerCount.Value” holds the number of players alive, so while that number is above 0, this should keep looping. The if statement just checks if the time has run out. Thing is, whenever I die or manually set the player count’s value to 0 or lower, it won’t stop the loop. I have tried doing:
while timePassed <= TimeLimit and playerCount.Value > 0
The problem with that one is that it will only stop whenever BOTH conditions have been done, and that’s what and does, so when I try to convert it to or like this…:
while timePassed <= TimeLimit or playerCount.Value > 0
That will keep looping until either the time has run out or the player count is lower than 0, but it still won’t work and I don’t understand why.
I have tried not() and also repeat until and every combination possible but it just won’t update. I have even tried making prints to see if it even reaches certain points on the code but it just won’t ever run the playerCount. I have triple checked that the playerCount is correctly hooked up to the INT variable. It all should work but strangely enough, it won’t.
Did try that, but it won’t stop the loop. It does stop when the time has run out but it does not stop whenever the plaeyr count reaches 0 (tried negative numbers as well just to see if that did anything but didn’t)
I think I found the mistake but still don’t know how to fix it.
the playerCount does reach 0, and the system does work, but this is where I believe the problem lies, this is the entire function:
function gameTimer()
playerCount.Value = MatchStats.totalCount.Value
--Enable matchInProgress so no one else can join
MatchStats.matchInProgress.Value=true
--Variable that stores the time that has passed.
local timePassed = 0
--Sets the status value.
status.Value = "Escape the rooms before the timer runs out!"
--Repeat until the ammount of time that has passed is less than the time limit.
while timePassed <= TimeLimit and playerCount.Value > 0 do
--Time left is equal to itself minus the time that has passed.
local TimeLeft = TimeLimit-timePassed
--Sets the status value with the remaining time.
status.Value = "You have "..TimeLeft.." seconds left to escape!"
--Add 1 more second to the time that has passed.
timePassed = timePassed+1
wait(1)
if playerCount.Value <= 0 then
print(playerCount.Value)
end
if playerCount.Value >= 0 then
print(playerCount.Value)
end
end
end
So I have two variables that store the number of players. one is totalCount that stores the total amount of players currently online, and there’s playerCount, that only stores the number of players when the round started, but I think it’s binding the two of them, but if that were true, then on the int value stored inside the script it would display a different number
Already tried that, I tried a repeat, a while, an if, a for, every type of loop and it still won’t work, but I believe it has something to do with the function I posted above.
The function gets called when the round begins.
I typed in those prints at the end just to be sure that the variable DOES get called, but it’s weird because on the part where I can change the variable on runtime it says 0 while on the console it’s printing 1, not 0. So it’s actually printing totalCount and not playerCount
The only other script that uses the variable is the one responsible for substracting 1 from playerCount whenever the player dies/leaves/wins while in a match