When you click the player's button on the playerlist information is displayed about them

Hi again, I am making a GUI with a custom playerlist which works perfectly, however I am trying to make it so when you click the player on the side it get’s information about the player stating their username, rank, User ID etc. However the function I have written does not work and I am unsure why. I get the output. "attempt to index nil with ‘Name’. Here is my script for reference.

local function getPlayerFromPartialName(PartialName)
	local FoundPlayer = 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
			FoundPlayer = PossiblePlayer.Name
		end
	end
end

for _,GetPlayers in pairs(Playerlist.ScrollingFrame:GetChildren()) do
	if GetPlayers:IsA("TextButton") then
		function OnButtonClicked()
			local Information = ModerateFrame.Information
			local GetPlayer = GetPlayers.Name
			local NewPlayer = getPlayerFromPartialName(GetPlayer)
			ModerateFrame.Notice.Visible = false
			ModerateFrame.Options.Visible = true
			Information.Visible = true
			Information.Header.Text = "Information on "..NewPlayer.Name
			Information.Rank.Text = "Rank: "..NewPlayer:GetRoleInGroup(ServerGroupID)
			Information.Username.Text = "Username: "..NewPlayer.Name
			Information.UserID.Text = "User ID: "..NewPlayer.UserId
			Information.Avatar.Image = Players:GetUserThumbnailAsync(NewPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		end
		GetPlayers.MouseButton1Click:Connect(OnButtonClicked)
	end
end

local NewPlayer = getPlayerFromPartialName(GetPlayer), NewPlayer returns nil, as you did not return the actual player in the function given.

local function getPlayerFromPartialName(PartialName)
	local FoundPlayer = 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
			FoundPlayer = PossiblePlayer.Name
            return FoundPlayer
		end
	end
end

If you’re setting a variable as the results of a function, remember to return them.

Hiya, thank you so much. But it hasn’t fixed my problem. I’m getting the output “attempt to concatenate string with nil

ServerGroupID is defined, right?

Regardless, which line is returning that error? Check the line (after the error in output, then check the line in your script.)

It was referring to the line which says

Information.Header.Text = "Information on "..NewPlayer.Name

I also tested with the :GetRoleInGroup and it said it wasn’t defined either so I am unsure.

try this

local function getPlayerFromPartialName(PartialName)
	local FoundPlayer = 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
			FoundPlayer = PossiblePlayer
		end
	end
	return FoundPlayer
end

for _,GetPlayers in pairs(Playerlist.ScrollingFrame:GetChildren()) do
	if GetPlayers:IsA("TextButton") then
		function OnButtonClicked()
			local Information = ModerateFrame.Information
			local GetPlayer = GetPlayers.Name
			local NewPlayer = getPlayerFromPartialName(GetPlayer)
			ModerateFrame.Notice.Visible = false
			ModerateFrame.Options.Visible = true
			Information.Visible = true
			Information.Header.Text = "Information on "..NewPlayer.Name
			Information.Rank.Text = "Rank: "..NewPlayer:GetRoleInGroup(ServerGroupID)
			Information.Username.Text = "Username: "..NewPlayer.Name
			Information.UserID.Text = "User ID: "..NewPlayer.UserId
			Information.Avatar.Image = Players:GetUserThumbnailAsync(NewPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		end
		GetPlayers.MouseButton1Click:Connect(OnButtonClicked)
	end
end

Thank you so much this works perfecty.

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