Detect if player's body part's have been clicked

I’m making a script where you can click a player and it gives information about the person’s game stats., the problem is that I can’t figure out how I’ve made a script that puts a ClickDetector in the person’s body parts but the script doesn’t work if anybody could help fix it, it would be appreciated!
The Script:

game.Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(game.Workspace[player.Name]:GetChildren()) do
		local click = Instance.new("ClickDetector")
		click.Parent = game.Workspace[player.Name][v.Name]
	end
end)

You dont need to put a click detector inside someones body. You can simply use a local script > and use userinputservice. Roblox wiki has an example of how to use this.

local UserInputService = game:GetService("UserInputService")
 
-- A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("The left mouse button has been pressed!")
	end
end
 
UserInputService.InputBegan:Connect(onInputBegan)

UserInputService (roblox.com)

After you activate the click all you do is check what its hitting and look to see if its matching up with a player.

I’ve never done this before I’m just wondering how do I check to see if its matching up with a player?

all you do is put the click detector in the model, and it should work for all parts in the model

You can make something like this:

LocalScript:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

function showStats(player)
    --Show
end

mouse.Button1Down:Connect(function()
    if not mouse.Target then return end

    local player = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
    if player then
        showStats(player)
    end
end)
1 Like

Does this script go into ScreenGUI?

why would the script go in a screengui, this isn’t even ui related

I don’t know but when I did put it there it worked

it works but it makes no sense to put it there

It can be in StarterGui(To automatically clone into PlayerGui). Is a localscript and you will need to reprogram the showStats function.