Get player from clicking a button

Sorry I constantly keep making posts. I am trying to make a GUI where you click a player on the player lists and it returns information about them. However I am struggling with what to write to get the player that you want information to be displayed about, Due to my lack of scripting knowledge some of my attempts are fairly mediocre I have tried to get the player by doing NewPlayer = Button.Name. I am oblivious to any other ways of doing this so if you can help I’d be very much appreciative. Here is my script so far. Feel free to correct any errors I have made.

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

it returns an error “attempt to concatenate string with Instance” I know this is the case because I have said which player but that is the exact point I am struggling with.

the NewPlayer variable is an instance, not a string, so you need to specify what string you want to concatenate. If you want to get the name of the player, for example, you can do…

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

OML, I am actually so unbelievably stupid. I made an entire post about something when I literally forgot one word. I am so sorry for wasting yout time LOL. I appreciate the effort you made tremendously, really thank you. HAHA

1 Like

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