Roblox global user search help

local TweenService = game:GetService("TweenService")

--[[function UpdateResults()
	local search = string.lower(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").Text)
	for i, v in pairs(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("ScrollingFrame"):GetChildren()) do
		if v:IsA("GuiButton") then
			if search ~= "" then
				v.Visible = false
				local item = string.lower(v.Text)
				if string.find(item, search) then
					v.Visible = true
					v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
					TweenService:Create(v, TweenInfo.new(0.7), {BackgroundColor3 = Color3.fromRGB(0, 0, 0)}):Play()
				end
			else
				--Checking if its pretty much empty
				v.Visible = false
			end
		end
	end
end]]--

--[[local UserService = game:GetService("UserService")

local success, result = pcall(function()
	return UserService:GetUserInfosByUserIdsAsync({ 156, 1, 735878936 })
end)

if success then
	for _, userInfo in ipairs(result) do
		print("Id:", userInfo.Id)
		print("Username:", userInfo.Username)
		print("DisplayName:", userInfo.DisplayName)
	end
else
	-- An error occurred
	warn("error line 22 - 38")
end]]


function makeButtonsFromPlayers(players,length,lookUpString)
	if string.lower(string.sub(players.Name,1,length)) == string.lower(lookUpString) then
		if players.name == lookUpString then
				
		else
			local id = game:GetService("Players"):GetUserIdFromNameAsync(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").Text)
			print(id)
			if id ~= "" then
				local name = game:GetService("Players"):GetNameFromUserIdAsync(id)
				print(name)
				local UserService = game:GetService("UserService")

				local success, result = pcall(function()
					return UserService:GetUserInfosByUserIdsAsync({id})
				end)

				if success then
					for _, userInfo in ipairs(result) do
						local clone = script:WaitForChild("PlayerExample"):Clone()
						clone.Parent = script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("ScrollingFrame")
						clone:WaitForChild("PLAYER_NAME").Text = userInfo.DisplayName
						clone:WaitForChild("PLAYER_USERNAME").Text = "@" .. userInfo.Username
						local content = game:GetService("Players"):GetUserThumbnailAsync(id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
					end
				else
					--error
					warn("error line 41 - 67")
				end
			end
		end
	end
end


script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox"):GetPropertyChangedSignal("Text"):Connect(function()
	local Type = script.Parent:WaitForChild("Sounds"):WaitForChild("Typing_Text"):Clone()
	Type.Parent = game:GetService("Workspace")
	Type:Play()
	Type.Ended:Connect(function()
		Type:Destroy()
	end)
	local lookUpString = script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").Text
	local children = game.Players:GetPlayers()
	local length = string.len(lookUpString)
	for _,players in pairs(children) do
		if script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").Text == "" then
			break
		else
			for i, v in pairs(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("ScrollingFrame"):GetChildren()) do
				if v:IsA("GuiButton") then
					v:Destroy()
				end
			end
		end
			makeButtonsFromPlayers(players,length,lookUpString)
		end
	end)


script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").Focused:Connect(function()
	local Type = script.Parent:WaitForChild("Sounds"):WaitForChild("Typing_Text_Select"):Clone()
	Type.Parent = game:GetService("Workspace")
	Type:Play()
	Type.Ended:Connect(function()
		Type:Destroy()
	end)
	script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	TweenService:Create(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox"), TweenInfo.new(0.7), {BackgroundColor3 = Color3.fromRGB(0, 0, 0)}):Play()
	script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox"):WaitForChild("SearchLabel").BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	TweenService:Create(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox"):WaitForChild("SearchLabel"), TweenInfo.new(0.7), {BackgroundColor3 = Color3.fromRGB(0, 0, 0)}):Play()
end)
script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):WaitForChild("SearchTextBox").FocusLost:Connect(function()
	local Type = script.Parent:WaitForChild("Sounds"):WaitForChild("Search_Enter"):Clone()
	Type.Parent = game:GetService("Workspace")
	Type:Play()
	Type.Ended:Connect(function()
		Type:Destroy()
	end)
	
end)

script.Parent:WaitForChild("MainFrame"):WaitForChild("StartSearchButton").MouseButton1Click:Connect(function()
	if script.Parent:WaitForChild("MainFrame"):WaitForChild("StartSearchButton").Visible == true then
		TweenService:Create(script.Parent:WaitForChild("MainFrame"):WaitForChild("StartSearchButton"), TweenInfo.new(0.5, Enum.EasingStyle.Sine), {ImageTransparency = 1})	
		wait(0.5)
		script.Parent:WaitForChild("MainFrame"):WaitForChild("StartSearchButton").Visible = false
		script.Parent:WaitForChild("MainFrame"):WaitForChild("Search").Visible = true
		--TweenService:Create(script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"), TweenInfo.new(0.7, Enum.EasingStyle.Sine), UDim2.fromScale(0.126, 0.455))
		script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):TweenSize(UDim2.new(0.346, 0,1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.7)
		script.Parent:WaitForChild("MainFrame"):WaitForChild("Search"):TweenPosition(UDim2.new(-0.363, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.7)
		local Sound = script.Parent:WaitForChild("Sounds"):WaitForChild("Swoosh"):Clone()
		Sound.Parent = game:GetService("Workspace")
		Sound:Play()
		Sound.Ended:Connect(function()
			Sound:Destroy()
		end)
	end
end)

help me with global roblox search
System.rbxm (23.4 KB)