hello, i want to check if mouse.hit finds a humanoid.
~maini
if mouse.Target:IsA(“Humanoid”) then
yes but the humanoid is in the dummy so it cant find it
if mouse.Target.Parent:FindFirstChildOfClass ("Humanoid")
if mouse.Target:IsA("Dummy").Humanoid then
Dummy is not a class you can use IsA on
uhh, never heard of a dummy class. Did u mean to do if mouse.Target:FindFirstChild("Dummy").Humanoid then
??
Overview
The underlying issue is that Mouse.Target
returns an Instance
of BasePart
, not models. You’d have to check the BasePart
’s Parent, which would be the Dummy model, if it contains a child of class “Humanoid”.
Corner Cases
This could error if you run Mouse.Target.Parent
when pointing at the sky, so you’d want to first check that Mouse.Target
is not nil
.
If you specifically want to use this function on Dummy models and not players, that would have to be another check in that if the Mouse.Target.Parent.Name
is something like "Dummy"
.
Example
if mouse.Target ~= nil then
local model = mouse.Target.Parent
if model:FindFirstChildOfClass ("Humanoid") then
print "Pointing at a model with Humanoid"
end
end