Weird flashing when grappling

I created some 3DMG, and manipulated HRP velocity to make grapple hooks.
There’s one issue tho, and its this:

notice that the character flashed a bit after i retracted the the hook.

Grapple Code:

self.StepConnection = RS.Heartbeat:Connect(function(dt)
	local CF = CFrame.new(self.FirePoint.WorldPosition,EndPoint.WorldPosition)
			
	local CurrentDirection = CF.LookVector
			
	if UIS:IsKeyDown(Enum.KeyCode.A) then
		CurrentDirection = -CF.RightVector
	end
			
	if UIS:IsKeyDown(Enum.KeyCode.D) then
		CurrentDirection = CF.RightVector
	end
			
	RP.Velocity = CurrentDirection * 50
end)

(i disconnect the connection when i retract the grapple)

If self.FirePoint.WorldPosition and EndPoint.WorldPosition happen to be the same, the results will be weird, because the LookVector of the CFrame can’t be calculated and it will be NAN, NAN, NAN. I’m not sure if this is the problem here, but I can’t think of any other reason to this.

Does this work?

self.StepConnection = RS.Heartbeat:Connect(function(dt)
	local CF
	local FirePointWorldPos, EndPointWorldPos = self.FirePoint.WorldPosition, Endpoint.WorldPosition
	if FirePointWorldPos == EndPointWorldPos then
		CF = CFrame.new(FirePointWorldos, FirePointWorldPos+RP.CFrame.LookVector)
	else CF = CFrame.new(FirePointWorldPos,EndPointWorldPos)
	end
			
	local CurrentDirection = CF.LookVector
			
	if UIS:IsKeyDown(Enum.KeyCode.A) then
		CurrentDirection = -CF.RightVector
	end
			
	if UIS:IsKeyDown(Enum.KeyCode.D) then
		CurrentDirection = CF.RightVector
	end
			
	RP.Velocity = CurrentDirection * 50
end)
1 Like

Nah, i actually just checked some debug tools (profiler and console) and it turns out that it wasnt any CFramy issues, but it was a lag spike that caused the flashing (sounds also stopped briefly). I resolved this issue by replacing the heartbeat connection with a coroutine while loop with a heartbeat wait to get the dt.

Thanks for your time tho

[will resolve]