Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

New raycasting is really weird with ray.Position?

function GetFloorMaterialFromPlayer(Player)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {Player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local ray = game.Workspace:Raycast(Player.Character.Head.Position, Vector3.new(0,-1,0), raycastParams)
	warn(ray.Position)
end


GetFloorMaterialFromPlayer(game.Players.ChicaLower)

It errors with it saying that ray is nil. It has something to do with FilterDescendantsInstances. Because when I change that to 1 part, it works. How do I ignore a whole character?

3 comments

0

Logically, if it wants parts, you give it each individual part of the player's Character. It doesn't sound terrible unless the player is using (oh god) R15.

0

can i just do unpack(player.character:getchildren())?

0

no, not needed, FilterDescendantsInstance filters descendants of given instance, Decsendants are all of the Instances which are inside of the Instance so {player.Character} is right.

1 answer

✓ Accepted answer

The not really new Raycast function returns RaycastResult OR nil, it only returns nil if nothing has been hit so all you have to do is check if the ray exists by doing

...
local ray = game.Workspace:Raycast(Player.Character.Head.Position, Vector3.new(0,-1,0), raycastParams)

if (ray) then
	print(ray.Position)
end

or by returns if the ray does not exist

...
local ray = game.Workspace:Raycast(Player.Character.Head.Position, Vector3.new(0,-1,0), raycastParams)

if not (ray) then
	return
end

print(ray.Position)

Otherwise your filter is right and you should not worry about it. The reason why it errored with only one part filtered because there was almost no change of ray not hitting the target.

4 comments

0

But the baseplate is under me, it should detect that the baseplate is there

0

Yeah it should and it will in your case, what exactly is the problem with that

0

Oh mate!! Your direction (2 argument of Raycast) is only one stud long, your character is in height of 5 studs so change that to somewhere at Vector3.new(0, -5, 0), that will solve it

0

oh, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.