Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago
Edited 8 years ago
1local mouse = game.Players.LocalPlayer:GetMouse()
2 
3if mouse.Target ~= nil then
4    if mouse.Target.Parent:FindFirstChild("Humanoid") then
5        print("FOUND HIM!")
6    end
7end

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

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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:

01function FindBase(top)
02    --you could upvalue workpace or use the preset global variable Workspace/workspace
03    local workspace = game:GetService("Workspace")
04 
05    while (top.Parent ~= workspace) do
06        top = top.Parent
07        --could add wait, if you wanted
08    end
09    return top
10end
11 
12local mouse = game.Players.LocalPlayer:GetMouse()
13 
14if mouse.Target ~= nil then
15    local base = FindBase(mouse.Target)
16        if (base:FindFirstChild("Humanoid")) then
17        print("Gotem coach")
18    end
19end
Ad

Answer this question