Issues with BodyGyro following mouse

Hello Devforum, so I have a tiny plane and I want it to follow my mouse using BodyGyro by getting the mouse position from the client, firing it into the server and use this code:
gyro.CFrame = CFrame.new(engine.Position,ms)

However, when I use this technique it doesn’t really follow it’s mouse and instead spins around as you can see in the video:

I have no idea how to fix this despite my research, I am sure the gyro has enough force to rotate the plane around. Here are my scripts:

Server

engine.Parent.Events.MousePosition.OnServerEvent:Connect(function(player,ms)
	local gyro = engine:FindFirstChild("BodyGyro")
	if gyro then
		gyro.CFrame = CFrame.new(engine.Position,ms)
	end
end)

Client

rs.Stepped:Connect(function()
	if en == true then
		local ms = mouse.Hit.Position
		local s = speed
		events.MousePosition:FireServer(ms)
		events.UpdateSpeed:FireServer(s)
	end
end)

All help and advise is appreciated, apologies in advance if I can’t get to you within the hour

1 Like

Could this be because there is no ground below? I’m not going off much here but you could try having a large invisible plate follow the character from below.

1 Like

Nope, the problem is still happening

If you print the mouse position does it look correct to you?

1 Like

Yeah, I don’t see anything unusual in the output when printing the mouse position:

Try this for your ServerScript:

engine.Parent.Events.MousePosition.OnServerEvent:Connect(function(player,ms)
	local gyro = engine:FindFirstChild("BodyGyro")
	if gyro then
		gyro.CFrame = CFrame.lookAt(gyro.CFrame.Position, ms)
	end
end)

Furthermore, I’d recommend looking at the Move event of the player’s mouse and bind the FireServer to that so it is not constantly firing server on each frame, but rather, when the mouse is moved (prevents it from firing the same position several times in a row). This may not align with your goals, but it would definitely be something to look at. Let me know if you have any further questions.

1 Like

Thank you for the advice, however the issue doesn’t seem to be fixed:

It looks like it looks at a direction but doesn’t look at the correct angle. How would I fix this?

Interesting. I’m not entirely certain as to why this happens, but I will do some testing in studio and get back to you.

1 Like