Hello! I have recently found that my jail script had a bug where mass resetting would cause the player to be released early due to starting a countdown that removes a minute from the jail stat every time. If I do this based on when the player is added the same problem is created by rejoining. On top of this when I tried to test starting the loop when the player was added if the player reset the loop ends. This is very strange behavior and I don’t understand how to work around these issues. Any suggestions you may have helps.
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
wait(1.5)
jailTime(plr,char)
end)
local MinutesRemaining = plr:WaitForChild("leaderboard").jailtimer
while wait(60) and MinutesRemaining.Value >= 0 do
MinutesRemaining.Value -= 1
if MinutesRemaining.Value == 0 then
MinutesRemaining.Value = -1
MuteUser:FireClient(plr, false)
wait(.1)
plr:LoadCharacter()
end
end
end)
The loop isn’t in jailtime, so any errors with it shouldn’t be caused there, especially since there are no more loops running. By mass resetting I just mean spamming the reset key makes multiple loops start and I can’t think of a way to only run the loop once per player without some hacky solution like some sort of boolean stored in the player.
to fix the mass resetting problem just add every jailed player to a table and every time the script is supposed to start the jailtime loop, use a for loop to cycle through the table and check if the player in question has already had the loop play for them.
at first it will be empty but you should use the jailtime function to add jailed players to the table so if they reset it will play again but it will notice it has already started a loop for them and will not start a new loop
maybe something like this:
Jailed = {}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
for index, player in pairs(Jailed)
if player == plr then return end -- check if player that was added is in table jailed
end
wait(1.5)
jailTime(plr,char) -- insert code into this function to add the player into Jailed preventing the loop from starting again
end)
local MinutesRemaining = plr:WaitForChild("leaderboard").jailtimer
while wait(60) and MinutesRemaining.Value >= 0 do
MinutesRemaining.Value -= 1
if MinutesRemaining.Value == 0 then
MinutesRemaining.Value = -1
MuteUser:FireClient(plr, false)
wait(.1)
plr:LoadCharacter()
end
end
end)