Weird bug with event completely breaking when it waits

basically i’m making a round leaderboard end system and if i dare put a task.wait() the entire script completely stops. not to mention it also removes all the clones when the player dies regardless of what resetonspawn is set to

here is my script:

UIEvents.LeaderboardRoundEnd.OnClientEvent:Connect(function(data)
	if data ~= nil then
		for Name, Points in pairs(data) do
			RoundLeaderboard.Main.Visible = true
			local New = RoundLeaderboardTemplate:Clone()
			New.Parent = RoundLeaderboard.Main.ScrollingFrame
			New.LayoutOrder = Points * -1
			New.Name = Name
			New.PlayerName.Text = Name
			New.Points.Text = tostring(Points)
			local content, isReady = Players:GetUserThumbnailAsync(Players:GetUserIdFromNameAsync(Name), Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
			New.Avatar.Image = content
			task.wait(5)
			New:Destroy()
			RoundLeaderboard.Main.Visible = false
		end
	else
		warn("Data is nil; Game continues")
	end
end)

thanks if u can help i’ve been trying to fix bugs with this system all day lol

Its not that your entire script stops, its that you are causing your loop to yield for 5 seconds before resuming. This means that each time you loop at least 5 seconds must pass; this is why your script seems to stop. Instead, you should offload the wait into a new thread, so you don’t yield the main thread. Luckily, the task library has this covered for you already with task.delay. It will look like this instead:

UIEvents.LeaderboardRoundEnd.OnClientEvent:Connect(function(data)
	if data ~= nil then
		for Name, Points in pairs(data) do
			RoundLeaderboard.Main.Visible = true
			local New = RoundLeaderboardTemplate:Clone()
			New.Parent = RoundLeaderboard.Main.ScrollingFrame
			New.LayoutOrder = Points * -1
			New.Name = Name
			New.PlayerName.Text = Name
			New.Points.Text = tostring(Points)
			local content, isReady = Players:GetUserThumbnailAsync(Players:GetUserIdFromNameAsync(Name), Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
			New.Avatar.Image = content
			task.delay(5, function()
				New:Destroy()
				RoundLeaderboard.Main.Visible = false
			end)
		end
	else
		warn("Data is nil; Game continues")
	end
end)


This issue still persists

Can i check the server script that links to this script??

local SharedPointsTable = require(ServerStorage.Modules.RoundModules.Tables.UniversalPointsTable) -- // Although it's only used in this script; I have had ideas in the past that I might incorporate in future updates that requires other scripts, So i'm just planning ahead of time.

AddPointEvent.Event:Connect(function(Player : Player, AmountOfPoints : number)
	if Player then
		SharedPointsTable[Player.Name] = (SharedPointsTable[Player.Name] or 0) + AmountOfPoints
		UpdatePlayerGUI:FireClient(Player, SharedPointsTable)
		print(SharedPointsTable)
	end
end)

BindableRoundEnding.Event:Connect(function()
	if SharedPointsTable ~= {} then
		print(SharedPointsTable)
		EndRoundGUI:FireAllClients(SharedPointsTable)
		table.clear(SharedPointsTable); SharedPointsTable = {}
		print("Successfully Ended!")
	end
end)

There is more but it consists of just defining things

-- // Services

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Players = game:GetService("Players")

-- // Events Folders

local EventFolderClient = ReplicatedStorage:WaitForChild("Events")
local EventsFolderServer = ServerStorage:WaitForChild("PrivateEvents")

-- // Events

local AddPointEvent = EventsFolderServer.AddPoint -- // Add Points via Server (Nobody trusts the client)
local UpdatePlayerGUI = EventFolderClient.UI_Events.AddPointGUI -- // Updates the GUI when a new point is added!
local BindableRoundEnding = ServerStorage.PrivateEvents.RoundEnding -- // So this script knows the game ends!
local EndRoundGUI = EventFolderClient.UI_Events.LeaderboardRoundEnd -- // Displays the leaderboard when the round ends

-- // Everything Else

local SharedPointsTable = require(ServerStorage.Modules.RoundModules.Tables.UniversalPointsTable) -- // Although it's only used in this script; I have had ideas in the past that I might incorporate in future updates that requires other scripts, So i'm just planning ahead of time.

AddPointEvent.Event:Connect(function(Player : Player, AmountOfPoints : number)
	if Player then
		SharedPointsTable[Player.Name] = (SharedPointsTable[Player.Name] or 0) + AmountOfPoints
		UpdatePlayerGUI:FireClient(Player, SharedPointsTable)
		print(SharedPointsTable)
	end
end)

BindableRoundEnding.Event:Connect(function()
	if SharedPointsTable ~= {} then
		print(SharedPointsTable)
		EndRoundGUI:FireAllClients(SharedPointsTable)
		table.clear(SharedPointsTable); SharedPointsTable = {}
		print("Successfully Ended!")
	end
end)

Shoe me where the add point event was fired

You mean end round? I don’t see how addpoint is necessary but i might be wrong, as there are other minigames there are different methods of adding them but all of them just fire a bindable event.

Here is end-round tho

						local FolderValue = FoundMap:WaitForChild("Data")
						
						if FolderValue then
							local timeValue = FolderValue:FindFirstChild("Time")
							for i = timeValue.Value, 1, -1 do
								local res = EndRound.CheckPlayers(FoundMap, SharedPlayerTable)
								StatusValue.Value = "GAME TIME: " .. i
								if res == true then
									print("<<< SERVER INFO: >>> Sending signal to signal end round")
									StatusValue.Value = "Ending Round"
									break
								end
								task.wait(1)
							end
						end
						
						ServerStorage.PrivateEvents.RoundEnding:Fire()
						EndRound.EndRound(FoundMap, SharedPlayerTable)

(didn’t mean to mark as solution just tabbed in oops)

This part about local content,isReady is strange

Just stick to local content

This is the break point.

The script thought that the whole data is belong to two things and is confused

Same issue still persists! -_-

Next part is Player:Player – are u seriously kidding me? They are the same !!!

It should be Player:player-- this part is to differentiate which player it belongs to

Again, That doesn’t change anything, The same issue is still happening where the frame literally closes after a fraction of a second!

I should clear up that Players is playservice! Also I don’t see how that changes it as you can still see the player thumbnail for a split second before it closes!

Show the video of frame ???(i need to see the progress

1 Like

I fixed it myself! I just added a delay via the server, Thank you sm for trying to help tho :happy2:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.