Script works so slowly

Hello,

I started making an admin panel where an admin can look up a user’s information if the user is in the game, the problem is it seems to work so slowly. Any ideas on why this is happening? I think this is because the script is having a hard time receiving user’s avatar picture from roblox.

Localscript:

local GUI = script.Parent
local TextBox = GUI.Frame.SearchBox
local PlayerInfo = GUI.Frame.PlayerINFO

local function GetPlayerFromPartialName(PartialName)
local foundname = nil
local Players = game.Players:GetPlayers()
for i = 1, #Players do
local PossiblePlayer = Players[i]
if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
foundname = PossiblePlayer.Name
end
end
if not foundname then
return nil
else
return foundname
end
end

local function HandleGUIOperations(player)
PlayerInfo.UserName.Text = player.Name
PlayerInfo.UserIDInput.Text = player.UserId
PlayerInfo.AgeInput.Text = player.AccountAge
local ThumbType = Enum.ThumbnailType.HeadShot
local ThumbSize = Enum.ThumbnailSize.Size100x100
local content, isready = game.Players:GetUserThumbnailAsync(player.UserId, ThumbType, ThumbSize)
PlayerInfo.AvatarPicture.Image = content
print(“hello found you haha”)
end

GUI.Frame.SearchB.MouseButton1Down:Connect(function()
local playername = GetPlayerFromPartialName(TextBox.Text)
if playername then
local playername1 = game.Players:FindFirstChild(playername)
if playername1 then
HandleGUIOperations(playername1)
end
else
TextBox.Text = “No player found!”
wait(1)
TextBox.Text = “Type here”
end
end)

Any feedback would be much appreciated!

Can you send me a video of what is happening?

1 Like

robloxapp-20210116-1309325.wmv (833.6 KB)

Copy and paste this script, hopefully it works

local GUI = script.Parent
local TextBox = GUI.Frame:WaitForChild("SearchBox")
local PlayerInfo = GUI.Frame:WaitForChild("PlayerINFO")

local function GetPlayerFromPartialName(PartialName)
	local foundname = nil
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local PossiblePlayer = Players[i]
		if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
			foundname = PossiblePlayer.Name
		end
	end
	if not foundname then
		return nil
	else
		return foundname
	end
end

local function HandleGUIOperations(player)
	PlayerInfo.UserName.Text = player.Name
	PlayerInfo.UserIDInput.Text = player.UserId
	PlayerInfo.AgeInput.Text = player.AccountAge
	local ThumbType = Enum.ThumbnailType.HeadShot
	local ThumbSize = Enum.ThumbnailSize.Size100x100
	local success,err = pcall(function()
		local content, isready = game.Players:GetUserThumbnailAsync(player.UserId, ThumbType, ThumbSize)
		PlayerInfo.AvatarPicture.Image = content
		print("hello found you haha")
	end)
	
	if not success then
		warn(err)
	end
end

GUI.Frame.SearchB.MouseButton1Down:Connect(function()
	local playername = GetPlayerFromPartialName(TextBox.Text)
	if playername then
		local playername1 = game.Players:FindFirstChild(playername)
		if playername1 then
			HandleGUIOperations(playername1)
		end
	else
		TextBox.Text = "No player found!"
		wait(1)
		TextBox.Text = "Type here"
	end
end)
1 Like

What’s the difference though, that one just uses a protected call which probably isn’t going to fix the slowness

I added some WaitForChild() too, maybe the GUI’s didn’t load properly yet. Anyways, test it out.

1 Like

Sadly, still the same. I bet this is because of gathering the avatar image takes ages

Can you send over the game file so I can test it?

Some stuff.rbxl (39.0 KB)

It works perfectly for me, maybe try testing it using Roblox Player and not in studio

1 Like

Yeah actually, that could be the case. Let me see.

1 Like