Hey, I was fixing some bugs in my game, and I discovered a bug.
Basically, If every single player but 1 leaves the game, I have a function that runs that stops the ongoing game, And teleports the player to the lobby, Then a wait for new players commences.
But there is an issue with this, I don’t really know how to put this into words other than having a seizure. Here’s a clip.
It like teleports the player hundreds of times, Even though I have a break in the if statement that stops after it runs the end-round script.
Here is my script:
if FolderValue then
local timeValue = FolderValue:FindFirstChild("Time")
ServerStorage.PrivateEvents.CustomLoader:Fire(FoundMap:GetAttribute("CustomLoadKey"))
for i = timeValue.Value, 1, -1 do
local CheckPlayersResult = EndRound.CheckPlayers(FoundMap, SharedPlayerTable)
StatusValue.Value = "GAME TIME: " .. i .. "\n"
if CheckPlayersResult == true then print("Ending here 999") break end
return
end
end
ServerStorage.PrivateEvents.RoundEnding:Fire()
EndRound.EndRound(FoundMap, SharedPlayerTable)
print("Ending Here 1009")
return
All the checkplayersresult module does is check if the amount of players in-game is less than 2, So I don’t feel like I need to include it, You can ask me though.
No, This is ran in the main game loop. This is a version that has comments. Apologies.
if FolderValue then
local timeValue = FolderValue:FindFirstChild("Time")
ServerStorage.PrivateEvents.CustomLoader:Fire(FoundMap:GetAttribute("CustomLoadKey")) -- This is before the match starts.
for i = timeValue.Value, 1, -1 do -- // This is for updating the status, And checking amount of players (every second)
local CheckPlayersResult = EndRound.CheckPlayers(FoundMap, SharedPlayerTable)
StatusValue.Value = "GAME TIME: " .. i .. "\n"
if CheckPlayersResult == true then print("Ending here 999") break end -- // Chekcing amount of players
task.wait(1)
return
end
end
ServerStorage.PrivateEvents.RoundEnding:Fire() -- // Table Stuff
EndRound.EndRound(FoundMap, SharedPlayerTable) -- // Ending
print("Ending Here 1009")
The bindable is just for table modifying, That is completely unrelated to this tho. (I replaced break with continue and it basically did the same thing just not ending)
i don’t see this print firing, one of your earlier functions must be doing it in a loop? could you post the implementation of the previous 2 functions?
wdym by the previous 2 functions? i’ll just post this entire part, and the module.
task.spawn(function()
local FoundMap = game.Workspace:FindFirstChild(TeleportResult)
if TeleportResult ~= false and FoundMap then
local FolderValue = FoundMap:WaitForChild("Data")
ServerStorage.PrivateEvents.ForceEndRound.Event:Connect(function(DB)
if DB == true then
ServerStorage.PrivateEvents.RoundEnding:Fire()
EndRound.EndRound(FoundMap, SharedPlayerTable)
print("Ending Here")
end
end)
if FolderValue then
local timeValue = FolderValue:FindFirstChild("Time")
ServerStorage.PrivateEvents.CustomLoader:Fire(FoundMap:GetAttribute("CustomLoadKey")) -- This is before the match starts.
for i = timeValue.Value, 1, -1 do -- // This is for updating the status, And checking amount of players (every second)
local CheckPlayersResult = EndRound.CheckPlayers(FoundMap, SharedPlayerTable)
StatusValue.Value = "GAME TIME: " .. i .. "\n"
if CheckPlayersResult == true then print("Ending here 999") break end -- // Chekcing amount of players
task.wait(1)
return
end
end
ServerStorage.PrivateEvents.RoundEnding:Fire() -- // Table Stuff
EndRound.EndRound(FoundMap, SharedPlayerTable) -- // Ending
print("Ending Here 1009")
return
else
return
end
end)
Module:
function Round.CheckPlayers(map, tbl : any)
if #tbl <= SettingsMod.RequiredToEndRound then
return true
else
return false
end
end
function Round.EndRound(ClonedMap : Model, PlayerTable)
if ClonedMap then
local s, e = pcall(function()
for index, ingamePlayers in ipairs(game:GetService("Players"):GetPlayers()) do
ingamePlayers:LoadCharacter()
end
if ClonedMap then
ClonedMap:Destroy()
ReplicatedStorage:WaitForChild("Events").Map_Events.Lighting:FireAllClients(2, nil);
table.clear(SharedPlayerTable)
SharedPlayerTable = {}
SettingsMod.EndRound = false
end
end)
if s then
return true
else
warn("<<< SERVER INFO >>> "..e)
return false
end
else
print("? Why isn't this existing? What?")
end
end
And this is privateevents
BindableRoundEnding.Event:Connect(function()
if SharedPointsTable ~= {} then
print("Ending")
task.wait(1)
EndRoundGUI:FireAllClients(SharedPointsTable)
table.clear(SharedPointsTable); SharedPointsTable = {}
end
end)
There doesn’t seem to be anything wrong with this, from what im seeing its caling endround multiple times? could you debug a little bit more, follow the call stack to the end, and see what it calls again, add a print at the beginning of Round.EndRound to see if it gets called multiple times, etc…
sorry im really dumb can you like rephrase that? if im right, what you’re saying to me is to print debug perhaps? earlier i tried a method, and it was printing Ending here 999 a bunch in the output. but im really confused on what you mean sorry
So if it doesn’t print inside the EndRound function multiple times, it shouldn’t be resetting your character multiple times, you could try setting the players cframe instead of resetting the player, instead of doing
for index, ingamePlayers in ipairs(game:GetService("Players"):GetPlayers()) do
ingamePlayers:LoadCharacter()
end
you can try
for index, ingamePlayers in ipairs(game:GetService("Players"):GetPlayers()) do
if not ingamePlayers.Character then continue end
ingamePlayers.Character.PrimaryPart.CFrame = --[[ reference to spawnpoint ]].CFrame
end