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

Attempt to use raycast for the first time, but it is not working?

Hello, I have been trying to see whether a player is under a part, so I've been trying to use raycast. I've never used it before, so the problem here might be really simple. I looked at the developer's page on it and copied some of the script there directly to mine, so idk what's going on :)

here is my script:

local function rayCast(origin,direction,ignoreTable)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = ignoreTable
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(origin,direction,raycastParams)
	if raycastResult then
		if not raycastResult.Instance.Parent:IsA("Accessory") then
			game.Lighting.FogEnd = 100000000
		else
			game.Lighting.FogEnd = 100
		end
	else
		game.Lighting.FogEnd = 100
	end
end


game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local head = char:WaitForChild("Head")
	while wait() do
		rayCast(head.Position,Vector3.new(0,-50,0),{workspace.Baseplate})
	end
end)

thank you for reading :)

1 answer

✓ Accepted answer

You need to ignore the character aswell, if you start from the head and shoot downwards, its going to hit the Torso or the HRP, to avoid the character you should add the descendants of the character within the whitelist. Good luck!

1 comment

0

Thank you

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