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

This mouse.Target local script doesn't work, why?!

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

if mouse.Target ~= nil then
	if mouse.Target.Parent:FindFirstChild("Humanoid") then
		print("FOUND HIM!")
	end
end

doesn't tell me anything, that's all of the code by the way.

1 answer

In some instances, if you targeted a players hat, the parent would be Head, which does not contain a Humanoid, if you want to find the humanoid, here is an example:

function FindBase(top)
	--you could upvalue workpace or use the preset global variable Workspace/workspace 
	local workspace = game:GetService("Workspace")

	while (top.Parent ~= workspace) do 
		top = top.Parent 
		--could add wait, if you wanted
	end 
	return top
end

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

if mouse.Target ~= nil then
	local base = FindBase(mouse.Target)
    	if (base:FindFirstChild("Humanoid")) then 
		print("Gotem coach")
	end
end

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