So I noticed that when I run the If statement to see if the there is a humanoid in the targets parent.
This line will not run.
It runs if there isnt a hum but it wont run if there is one.
Why is this happening??
-- detect for a player
local origin = char.PrimaryPart.Position
local root = char.PrimaryPart
-- where the ray fires to
local rayDirection = origin + root.CFrame.LookVector * 15
local part = Instance.new('Part')
part.Parent = workspace
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part.Position = rayDirection
game:GetService('Debris'):AddItem(part,3)
-- send the raycast
local raycastResult = workspace:Raycast(origin, rayDirection)
if raycastResult then
print('Casted')
local target = raycastResult.Instance
if target.Parent:FindFirstChild('Humanoid') then -- THIS IS NOT RUNNING WHYYYYY
print('There is a hum')
local hitChar = target.Parent
local Hithum = hitChar.Humanoid
local Hitroot = hitChar.PrimaryPart
Hitroot.CFrame = CFrame.new(Hitroot.Position,char.PrimaryPart.Position)
local charCframeToGoTo = Hitroot.CFrame * CFrame.new(0,0,10)
char.PrimaryPart.CFrame = charCframeToGoTo
else
print('No hum')
end
end
I just realized that now its not really even working. Why is this happening?
Also it mostly doesn’t work if it is in a certain direction