Raycasting, getting a player when a Ray hits them

after that line print(Humanoid)

after this line print(humanoid)

1 Like

and it doesn’t print out anything lol

wait wait what not even humanoid ?

1 Like

Just checking are you using local script or script

1 Like

i’m using a normal script lolol

Now i need you to do something as I need to know where it stopped.
Can you try to print something every 3 lines?

1 Like

it stops at “hi3”

if raycastResult then
		print("hi1")
		local RayInstance = raycastResult.Instance
		if RayInstance then
			print("hi2")
			local character = RayInstance.Parent.Parent
			if character then
				local humanoid = character:FindFirstChild("Humanoid")
				if humanoid then
					print("hi3")
					humanoid:TakeDamage(10)
				end
			else
				character = RayInstance.Parent
				if character then
					print("hi4")
					local humanoid = character:FindFirstChild("Humanoid")
					print(Humanoid)
					if Humanoid == nil then
						print("hi5")
						Humanoid = RayInstance.Parent.Parent
						print(Humanoid)
						if humanoid then
							print("hi6")
							humanoid:TakeDamage(10)
						end
					end
				end
			end
		end
	end

humanoid:TakeDamage(10)
after that print(“hi idk”)
and before that print(humanoid)

1 Like

you’re on to something when i faced sideways it stopped printing “hi3” and “hiidk” and it doesn’t print the humanoid when i facesideways. yeah it prints “hi2” and “hi1”

but it printed “hi2” ?

yes i tried putting :heart: (char)

1 Like

print(character)? as it’s sus cuz if thats the case then character would be workspace but it shouldnt be

2 Likes

print(character) prints out “Workspace”

Exactly BRO FOR 30 MINS I SUSPECTED THIS

1 Like

change this to

local character = RayInstance.Parent
1 Like

yeo now it works! BUT now it’s not damaging the player when i’m facing it :sad:

1 Like

I see.

change into

if RayInstance.Parent.Parent.Name == "Workspace" then
character = RayInstance.Parent
else
character = RayInstance.Parent.Parent

end

if this doesnt work then im gonna change the script into the turret killing me instead

5 Likes

LETSS GOOOO IT WORKS!!! WHOOO FINALLY I SPENT 2 WHOLE DAYS TRYING TO FIGURE THIS OUT THANK YOU, also thanks jack and atscripterboy !!!

3 Likes

yes i love life now after 1 hour

2 Likes

How the heck did the Parent make it to the game property what

2 Likes

because when it hits the arm then it will return arm
and arm.Parent.Parent is Workspace

but when it is facing foward then it may hit Handle
Which Handle.Parent.Parent would be Character

2 Likes