Attempt to index nil with 'Distance'

Hello,

I am making a move where the player throws a magma ball; This works with my current script but after a few usages of the move, it breaks and gives me the error “Attempt to index nil with ‘Distance’”.
Here’s the Module Script:

local Moves = {}

function Moves.magmaBall(ball,TITime,humanoidRootPart)
	ball.CFrame = humanoidRootPart.CFrame
	local raycastparams = RaycastParams.new()
	raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycast = workspace:Raycast(humanoidRootPart.Position,humanoidRootPart.Position + Vector3.new(0,100,0),raycastparams)
	local goals = {["Position"] = raycast.Distance*raycast.Normal} -- error line
	local tweenService = game:GetService("TweenService")
	local TI = TweenInfo.new(TITime)
	local track = tweenService:Create(ball,TI,goals)
	track:Play()
	track.Completed:Connect(function()
		ball:Destroy()
	end)
end
return Moves

I am grateful for any type of help in this situation!

1 Like

workspace:Raycast returns nil if no valid parts are hit
you’ll need to account for that in your function

1 Like