How To Add Cooldowns To Interval

So I have a script that loads my charlist (a local script in a gui that loads in the user id’s username and avatar thumbnail) the script works but the issue is it breaks because I’m sending too many requests too fast so how can I add a cooldown so the script doesn’t send all the requests at the same time??

local f = script.Parent:GetDescendants()
local Players = game:GetService("Players")

for i,id in pairs(script.Parent:GetDescendants()) do
	if id.Name == "UserId" then
		-- String
		id.Parent.Text = Players:GetNameFromUserIdAsync(id.Value)
		id.Parent.PlaceholderText = Players:GetNameFromUserIdAsync(id.Value)
		-- Png
		local ImageSize = Enum.ThumbnailSize.Size420x420
		local ImageType = Enum.ThumbnailType.AvatarThumbnail
		local content = game.Players:GetUserThumbnailAsync(id.Value, ImageType, ImageSize)
		id.Parent.PlayerPng.Image = content
1 Like

Might consider adding a task.wait(your delay value) under your last line.

id.Parent.PlayerPng.Image = content

task.wait() --< added task.wait to delay script without throttling to prevent the breaking

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