Turret stops running when pointed at sky

hihi, i’ve managed to fix the Minigun stationary so the whole point is to make sure minigun aims at sky even if it returns nil but somehow breaks after aiming at the sky, tried looking for another solution but nothing matched to what i was looking for plus it’s using part to point at where the turret should point.

By far, everything is working fine and there’s no errors but the only problem here is the turret stops running until cursor points at every Instance in the workspace, the green part in the video shows where the cursor is pointed at.
here’s how it functions

-- code here is not a full one, showing the relevant ones (this one is server-side script translated to LocalScript using RunContext)
local function cast_mouse(blacklist)
	local rayPOS = inputSV:GetMouseLocation()
	local raycaster = cam:ViewportPointToRay(rayPOS.X, rayPOS.Y)
	
	
	local rayPARAM = RaycastParams.new()
	rayPARAM.FilterType = Enum.RaycastFilterType.Blacklist
	rayPARAM.FilterDescendantsInstances = blacklist
	
	local rayRE = workspace:Raycast(raycaster.Origin, raycaster.Direction * 5000, rayPARAM)
	
	return rayRE
end

local function clonePOINTER()
	local pointerMain = replicatclient.partINS:FindFirstChild("tar")
	if pointerMain then
		pointer = pointerMain:Clone()
		pointer.Parent = workspace.PartIndicator
	end
end
note that there is no GetMouse being used as it’s deprecated

Make sure to return a position of where the ray will end up if there is np raycast result.

Something like this function to get mouse position with the newer raycast:

though this has been checked out but it causes the error as it expects Vector3, through rendering, Raycast result is rendered inside RunService function so this can’t return the hit position.
here’s where it’s re-positioning.

task.spawn(function() -- spawns task to prevent this from running first
	runSV.RenderStepped:Connect(function(step)
		if pointer then
			local currentPoint = cast_mouse({pointer, player_crv.Character})
			if currentPoint then
				local X = currentPoint.Position.X
				local Y = currentPoint.Position.Y
				local Z = currentPoint.Position.Z

				local cfram_3d = CFrame.new(X,Y,Z)
				pointer:PivotTo(cfram_3d)

				local goalPos = pointer.Position
				BaseRotator:LookAt(goalPos ,step)

				barrel.C0 *= CFrame.Angles(3,0,0)
				--remotPOS:InvokeServer(tar.Position)
			end
		end
	end)
end)

EDIT: turns out i don’t have to move and sort variables again, it now turns around perfectly!
my bad thought it didn’t solve the issue :sweat_smile:

External Media

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