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

How do I find the "subject" of mouse.Target?

Asked by 3 years ago

OKAY OKAY OKAY, let me explain this in detail. In this script i am Attempting to either delete a part, or write the message "the target was human" if the "target" has the humanoid child in them. However....... I am having an EXTREMELY hard time figuring out how to find if the part has a humanoid inside of it. The most recent error being :

"Players.snipperdiaper.Backpack.Tool.LocalScript:8: attempt to index nil with 'FindFirstChild'"

which I cant figure out how to fix. So any help is appreciated!

local player = game.Players.LocalPlayer
local tool = script.Parent
local mouse = player:GetMouse()


tool.Activated:Connect(function()
    local target = mouse.Target
    local HumanoidFactor = target:FindFirstChild("Humanoid")

    if target ~= HumanoidFactor then

        target:Destroy()

    elseif target == HumanoidFactor then

        print("The Target was human")
    end


end)



Thanks in advance, Snipperdiaper

Answer this question