Player not following cursor

Hey! I’m using a Cursor Following system and for some reason, when the player it’s not close to the blasepate it starts looking forward and there’s no way that it continues following the cursor.

I’ve tried to make a system to save the last position of the cursor but stills rotating when it doesn’t detects the baseplate.

Someone knows why it’s this happening?

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local Mouse = player:GetMouse()
Mouse.TargetFilter = workspace.Ignore

local savedCursorPosition = nil

Mouse.Move:Connect(function()
	savedCursorPosition = Mouse.Hit.Position
end)

local function updateCamera()
	local character = player.Character
	if character then
		local root = character:FindFirstChild("HumanoidRootPart")
		if root and savedCursorPosition then
			local newYTarget = root.Position.Y
			root.CFrame = CFrame.lookAt(root.Position, Vector3.new(savedCursorPosition.X, newYTarget, savedCursorPosition.Z))
		end
	end
end

game:GetService("RunService").RenderStepped:Connect(updateCamera)

I pasted your exact code into my own script, but removed the mouse ignore part. It worked perfectly, I think there is a problem with that part of your code.

EDIT: looking at your video right now, it looks like your mouse is passing through all the builds and hitting the baseplate infront of you. Because of the camera angle it makes your character look forward, I’m going to try to come up with a solution right now.

hi, im stuck and dont have the time for a proper solutioon. all i could think of is removing the mouse filter let me know if it works!

The problem is if I remove that, the player would rotate towards the part I’m pointing

The player rotates to the front cause it doesn’t detect the baseplate basically, since when I jump high as well the player looks at the front.

sorry for the late reply i’ve been coming up with this code the whole time. the solution is a bit hacky but it should work just fine. here is the updated code:

local Players = game:GetService("Players")
local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera

local player = Players.LocalPlayer

local part = Instance.new("Part")
part.Size = Vector3.new(200,1,200)
part.Anchored = true
part.Transparency = 1
part.CanCollide = false
part.CanTouch = false
part.Name = "plrMouseDetector"
part.Parent = workspace

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {part}

local function updateCamera()
	local character = player.Character
	if character then
		local root = character:FindFirstChild("HumanoidRootPart")
		if root then
			part.CFrame = CFrame.new(root.Position)

			local mousePos = userInput:GetMouseLocation()
			local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
			local result = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, params)
			
			if result then
				local newYTarget = root.Position.Y
				root.CFrame = CFrame.lookAt(root.Position, Vector3.new(result.Position.X, newYTarget, result.Position.Z))
			end
		end
	end
end

game:GetService("RunService").RenderStepped:Connect(updateCamera)

you can increse the part size if needed. if the camera gets too far and the mouse doesnt detect the part the character will move like normal

1 Like

disable autorotate on the humanoidd

could just be because baseplate is locked but idk tho

Change the filter type to exclude and put the part in the list but I am pretty sure you’d have to rewrite some code.

I’ve managed to fix it, basically I had to add a part named plrMouseDetector to the workspace, anchored it down the baseplate and add it to the ignore list in my script.

1 Like

Thank you very much! I was looking to do something similar to this, but you saved me! :heart:

1 Like