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 7 years ago
Edited 7 years ago
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

Log in to vote
0
Answered by 7 years ago
Edited 7 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:

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

Ad

Answer this question