Raycasting, getting a player when a Ray hits them

wait wait what’s the issue now

1 Like

how is your post getting flagged?!

it’s pretty much not damaging the player when the player is facing sideways towards it

If you face sideways, are there any errors?

1 Like

nah there’s no errors it just keeps printing “Handle” and “Head”

How about when it damages you?
And what line does it print Handle and Head

1 Like

it damages me when i get close to it and the only thing it prints are handle and head. and it prints at this line

if raycastResult then
		local RayInstance = raycastResult.Instance
		print(RayInstance)

try increasing the magnitude to about 250

1 Like

yeah increasing the range wouldn’t do anything i think it’s because of the ray hitting the arm and it doesn’t know what to do after that

uh put print character after if character then
cuz i think im getting it

1 Like

bam, now it just prints Head lol

eeee how do i take off the (post withdrawn by author, will be automatically deleted in 1 hour unless flagged) thingy

1 Like

wait so does it even hit once if you face sideways

1 Like

it hits and it prints “head” but it doesn’t damage the player

Uh update your script yes cuz it’s been long

1 Like

update

local part = script.Parent
local partmodel = workspace.Workerthrow



while wait(1) do
	for i, v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Head")
		if human and torso and human.Health > 0 then
			if (torso.Position - part.Position).magnitude < 250 then
				part.CFrame = CFrame.new(part.Position, torso.Position)
			end	
		end
	end
	local origin = part.Position
	local direction = part.CFrame.LookVector * 250

	local raycastParams = RaycastParams.new()

	raycastParams.FilterDescendantsInstances = {part, partmodel}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(origin, direction, raycastParams)
				
	if raycastResult then
		local RayInstance = raycastResult.Instance
		print(RayInstance)
		if RayInstance then
			local character = RayInstance.Parent.Parent
			if character then
				local humanoid = character:FindFirstChild("Humanoid")
				if humanoid then
					humanoid:TakeDamage(10)
				end
			else
				character = RayInstance.Parent
				if character then
					print(character)
					local humanoid = character:FindFirstChild("Humanoid")
					if Humanoid == nil then
						Humanoid = RayInstance.Parent.Parent
						if Humanoid then
							Humanoid:TakeDamage(10)
						end
					end
				end
			end
		end
	end
end

do

if Humanoid == nil then
						humanoid = RayInstance.Parent.Parent
						if humanoid then
							humanoid:TakeDamage(10)
						end

just trying cuz im not good at raycasting

1 Like

still does the same thing for some reason

oops! changed the wrong 1

if Humanoid == nil then
						Humanoid = RayInstance.Parent.Parent
						if humanoid then
							humanoid:TakeDamage(10)
						end
1 Like

andddddddddddddd still does the same thing