Problem with Getting Position of Raycast Result

Simply put, I cant seem to access the Position of a Raycast Im making
Whenever I try to do arithmetic with it, it constantly states it as ‘nil’
I tried printing it out and apparently theres two values?
image
image

I’ll be up late so I should be able to answer any questions for tonight, sorry if this wasnt clear enough, just ask and I’ll try my best to explain better.

1 Like

can you provide the rest of the code?

also make sure you are reading .Position of the RaycastResult returned by :Raycast()

1 Like

Without any other code me and a lot of others can not help you. Please provide the raycast code

1 Like

I hope the use of screenshots is alright for the time being

BStart is an attachment
Direction takes the players Mouse

And RaycastResultPosition is just Bullet.Position

1 Like

Is there a check for if there is actually a raycast result?

1 Like

Could you show more of the code?

1 Like

Try (BStart-Mouse.Hit.Position).Unit for the direcion

1 Like

The code looks correct so the problem is probably that the racyast isnt actually hitting anything

1 Like

I have a message thats pending for an absurd amount of time for moderation for some reason
But it just said that
The code is simply just me making a raycast, passing the position into a function, and then printing it

2 Likes

I meant to ask what mathematics you were doing on it.

I was aiming at a wall when doing this, and it did seem to print the actual position of the raycast, but it also prints nil at the same time?
Which in turn just marks it as nil instead

Just this

Can you copy paste all of the relevant code here? (use preformatted text (ctrl + e))

Oh wait, theres also this, It should just handle if the raycast if pointed at the sky, could this be the problem?
(sorry for forgetting about this in the first place)

if not Bullet then
		
		EndPos = BStart + Camera.CFrame.LookVector * RANGE
		
	else
				
		EndPos = Bullet.Position
		
	end

The entirety of the code that should be relevant now

function RenderClientBullet(Origin, RaycastResultPosition)

	print(RaycastResultPosition)
	
end

function FireClientBullet()
	
	local EndPos
	local BStart = FlashParticle.Parent.WorldPosition
	local Direction = (Mouse.Hit.Position - BStart).Unit
	local Bullet = workspace:Raycast(BStart, Direction * RANGE, Parameters)
	
	if not Bullet then
		
		EndPos = BStart + Camera.CFrame.LookVector * RANGE
		
	else
				
		EndPos = Bullet.Position
		
	end	
	
	if Bullet then
		
		RenderClientBullet(BStart, Bullet.Position)
		
	end
		
	
end

I found a work-around at least,
Instead of passing the position of the raycast into the function, ill just do what I want with the position in the same block of code instead
Yet for some reason the position is fine until I pass it into a function, which then it becomes two values (the Vector3 and nil)