Create raycast from HumanoidRootPart to Position

So in short I’m trying to validate if a raycast is legit (not going through walls) and I currently created this script:

function RaycastIsVerified(RaycastParameters, RaycastResult, Player, Length)
	local Character = Player.Character
	local StartPosition = Character:FindFirstChild("Head").Position
	local EndPosition = RaycastResult.Position

These are the parameters in the script above:

	local RaycastParameters =
	RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist
	RaycastParameters.FilterDescendantsInstances = GatherIgnoredRaycastParts(Player.Character)
	RaycastParameters.IgnoreWater = false

	local RaycastResult = WorkspaceService:Raycast(CameraInfo.Origin, CameraInfo.Direction*Length, RaycastParameters)

--Player is just the player that fired the remote that eventually created the ray and length is always 100.

I have no idea what to do in the RaycastIsVerified function.

Also for more info, RaycastResult is a 3D world position that’s not verified. This means the player can use shiftlock and click through walls. I want to make an ‘extra safety step’ I suppose to stop exploiters from removing walls and being able to shoot/click through them.


Is it something you are trying to verify for debugging? Or does it need to verify ingame.

For debugging you can instead just create a part at the results position to get a visual indicator.

If it needs to verify in game, you can just cast a new ray inside the raycast is verified function from the parameters youbpassed in and make it return whether that raycast hit something or not.

It isn’t for debugging but I’m not sure how to cast a ray with the given parameters.

so youve already casted a ray when you declared RaycastResult. It is a array which has info on what it hit. So you can do something like this

if RaycastResult then

I figured that out, sorry for not disclosing this earlier I just thought it didn’t matter, but the RaycastResult parameter is a ray formed from a 2D click (from clicking on their screen, etc) to a 3D world position.

I wanted to create the RaycastIsVerified function so I could make sure that the player isn’t using shiftlock to click through walls/exploiting by removing walls.

Well thats simple just fire the ray cast from the head of the player instead of the camera

I don’t know anything math related so I don’t know how to do it.

Raycast results from Camera:

	local RaycastResult = WorkspaceService:Raycast(CameraInfo.Origin, CameraInfo.Direction*Length, RaycastParameters)

Verify raycast results using Player’s head:

local VerifyRaycastResult = WorkspaceService:Raycast(Character.Head.Position, --don't know how to get raycast direction or cframe or whatever, RaycastParameters)

Make the origin of the ray be the players heads position

Alright I have that now, ty.

I just don’t know how to get the direction thingy I guess.

watch my video on vectors - YouTube

1 Like