Ability to click players?

So I was wondering how I would approach this type of method, like clicking on a player and just a gui would pop up, and get that player’s name and basic info such as, userid, username, account_age and others. and I was wondering if there is any tutorial or something related to this that could help.

6 Likes

I’m not sure but I think you have to place a click detector in the character for a start

1 Like

Yes, but you can’t really parent a clickDetector to the character, since it won’t work.

1 Like

It does work. I have put ClickDetectors inside models, and it makes the whole thing clickable.

It’s even documented:

3 Likes

Hello, I suggest you to use Raycast for the function you’ve said above.

I recently made arresting GUI using Raycast to detect click on player, it works perfectly fine as I’ve intended.

I suggest you reading RaycastParams and Intro to Raycasting if you are new to raycasting! Let me know if you need any further help, any questions are welcomed.

2 Likes

Oh, well I read more about it so I just inserted one in the HumanoidRootPart, but still how would I get a the informations about the user?

2 Likes

A simple way of doing this could be by creating a hitbox around the player every time they spawn, then add a click detector. Not sure if this method would cause lag, though.

1 Like

You can get the user’s information by using:

local clickedPlayer = game:GetService("Players"):GetPlayerFromCharacter(TheCharacterModelInWorkspace)

and all of the information you’re looking for is from the player’s properties.

1 Like

I know this is off-topic but how did you get that page to look like that? Mine looks like this

1 Like

I would suggest you place a Click Detector into the players HumanoidRootPart each time they spawn in.

Then you can add a basic .MouseClick() function to detect when the part gets clicked.

I suggest adding checks (Raycasts, Magnitude Checks, etc.) to prevent possible lag or abuse.

1 Like

Why not just use mouse.Target to check if they’re a player.

5 Likes

As @Ukendio had said, use mouse.Target.

It’s a much more simplistic way of going about this than RayCasting.
RayCasting isn’t a bad way to do it, but mouse.Target is just infinitely easier and requires less guessing to find the target.

All done on local Script
Create a click detector with a hover over effect that makes a selection box around the player.

This means that it will give you a cool sort of animation when the player hovers over a player. The click detector wont actually do anything apart from show the selection box and remove it. The gui will be brought up from the Mouse.Button1Down Event.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()
     local Model = Mouse.Target:FindFirstAncestorOfClass("Model")
     if Model == nil then
          -- Its not in a model
     else
          local Players = game:GetService("Players"):GetChildren()
          for i = 1,#Players do
               if Players[i].Name == Model.Name then
                    -- This player has been clicked on
               end
          end
     end
end)
3 Likes

This is a local script inside StarterPlayerCharacter > StarterPlayerScripts

This will print their Name and UserId.

(Deleted my last reply because of a mistake.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")


uis.InputBegan:Connect(function(key,IsTyping)
	if not IsTyping then
		if key.UserInputType == Enum.UserInputType.MouseButton1 then
			local Model = mouse.Target:FindFirstAncestorOfClass("Model")
			if Model then
				local ThePlayer = game.Players:GetPlayerFromCharacter(Model)
				if ThePlayer then
					print(ThePlayer)
					print(ThePlayer.UserId)
				end
			end
		end
	end	
end)
10 Likes

Here is a good way on doing so. Make sure this local script is in starterplrscripts

local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local char = plr.CharacterAdded:Wait()
Mouse.Button1Down:Connect(function()
if mouse.Target == char.Humanoid then
-- gui popup or watever u wanna do here, fire a remote if you dont want important info being messed with.
end
end)
1 Like

You can check if they clicked with a click detector. Then you can check if the mouse.Target.Parent:FindFirstChild(“Humanoid”). After that you can check if mouse.Target.Parent.Name is a valid player name. They you have have info on the player popup.

2 Likes