Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ROBLOX not registering clicking other player?

I am trying to make Roblox show a GUI when you click another player and it does not print my print statement

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	if Mouse.Target.Parent:FindFirstChild("Humanoid") then
		local clickedPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
		print(Mouse.Target.Parent.Name)
	end	
end)

2 comments

0

make sure your script is enabled (it happens easily that you deactivate scripts to check something and then forget to turn them back on)

0

script.Disabled is false

1 answer

Works perfectly fine for me proof

But i recommend adding this (it prevents a error when you click at something that is nil / e.g the sky):

if Mouse.Target then

end

How it would look in the script:

Mouse.Button1Down:Connect(function()
	if Mouse.Target then
	    if Mouse.Target.Parent:FindFirstChild("Humanoid") then
	        local clickedPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
	        print(Mouse.Target.Parent.Name)
	    end 
	end
end)

7 comments

0

I now get this error: Workspace.Player2.Ragdoll:145: attempt to index local 'Humanoid' (a nil value)

0

is this in a local script or server?

0

A local script

0

ok on line "145" what is its code? is it "if Mouse.Target.Parent:FindFirstChild("Humanoid") then" ? "local clickedPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)" ? "print(Mouse.Target.Parent.Name)" ? etc

0

yea

0

i don't know if these errors relate:

0

Error checking in group: Player:GetRankInGroup failed because HTTP 0 (HTTP 400) Error checking in group: Player:IsInGroup failed because HTTP 0 (HTTP 400) Error checking in group: Player:GetRankInGroup failed because HTTP 0 (HTTP 400) Error checking in group: Player:IsInGroup failed because HTTP 0 (HTTP 400)

This discussion is preserved as it was. New answers, comments, and votes are closed.