Intro to Raycasting

PHOTO EMBED

Fri Jan 08 2021 19:39:02 GMT+0000 (Coordinated Universal Time)

Saved by @TheCoderrrrrrrr #lua

local function fireLaser()
	-- Set an origin and directional vector
	local rayOrigin = caster.Position
	local rayDirection = Vector3.new(0, -100, 0)
 
	-- Build a "RaycastParams" object and cast the ray
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {caster.Parent}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
 
	if raycastResult then
		local hitPart = raycastResult.Instance
		-- Check if the part resides in a folder, that it's fully visible, and not locked
		if hitPart.Parent == workspace.Tiles and hitPart.Transparency == 0 and not hitPart.Locked then
content_copyCOPY

https://developer.roblox.com/en-us/articles/Raycasting