Workspace.Landmine.PlantBomb:146: attempt to index nil with 'Instance'

For some reason I keep getting that exact error that Is mentioned in the title. I’m not sure what “attempt to index nil” is supposed to mean, so can anyone help me fix this error? Because I’m trying to make a raycast for a landmine.

function setUp(bombClone, user)
	raycastParams.FilterDescendantsInstances = {bombHandle, user.Character}

	bombClone.Anchored = false
	
	local origin = bombClone.Position
	local direction = Vector3.new(0,2,0)

	local raycastResult = workspace:Raycast(origin,direction)

	local raycastVisual = Instance.new("Part")
	raycastVisual.BrickColor = BrickColor.new("Persimmon")
	raycastVisual.Transparency = .5
	raycastVisual.Anchored = true
	raycastVisual.Size = Vector3.new(.5, 2, .5)
	raycastVisual.Position = bombClone.Position
	raycastVisual.Parent = bombClone.Parent

	while task.wait() do
		raycastResult = workspace:Raycast(origin, direction, raycastParams)
		origin = bombClone.Position
		direction = Vector3.new(0,2,0)
		
		print(raycastResult)
		if raycastResult.Instance then
			if game.Players:GetPlayerFromCharacter(raycastResult.Instance.Parent) then
				explode(bombClone, user)
			end
		end
	end
end
2 Likes

The error is saying that raycastResult is nil.
Instead of doing

if raycastResult.Instance then

try doing just

if raycastResult then

to remove the error

3 Likes

you working with raycast and you don’t know what the error means?

1 Like

Thanks for helping me solve my problem. Haven’t used ray casting in months because I’ve been on a bit of a hiatus so I kind of forgot a lot of things after not practicing after all of that time…

1 Like

I would have most likely not make a post about this If I still had that knowledge of raycast in mind.

Also, don’t assume that everyone knows a specific thing like making a comment about someone not knowing why they got an error for something like tween service.

If I still had that knowledge of raycast in mind.

you don’t need to know raycast to know what attempt to index nil means

the reason i ‘assumed’ is because usually when you know/worked with stuff like raycast, you’d know what that error means

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.