local gameStart = tick()
for i = Timer, 1, -1 do
game:GetService("RunService").Heartbeat:Wait()
Timer = config.RoundTime - math.round((tick() - gameStart))
local mins = math.floor(Timer / 60)
local secs = Timer - (mins * 60)
statusValue.Value = mins..":"..secs
for i, player in pairs(tableplayers) do
pcall(function()
if not player.Character:FindFirtsChild("ConfirmPlaying") then
table.remove(tableplayers, i)
end
end)
end
if #tableplayers == 0 then
Timer.Value = "All the players have died"
task.wait(2)
break
end
task.wait(1)
end
The truth is I don’t get any errors but I want to know if there is a cleaner method
If it works properly, it’s programmed correctly. If you’re concerned about the validity of the script itself, just stress-test it to make sure it works properly.
If it’s optimally clean? Probably not. Why does it have to be, though? If you spend all of your time worrying about optimizing everything you will get nothing done.
After all, premature optimization is the root of all evil, said a smart man Donald Knuth, whom may or may not be one of the greatest computer science figures to ever live.
To answer your question, yes, it’s fine.
But - why wrap that particular function in a pcall? If it’s prone to errors and you’re using that to ignore them, perhaps you want to reevaluate that part of your script? I don’t see any major issues. Again, just stress-test your code. You will be able to fix it if it’s not working.