How can I fix this error with mouse.Hit?

Hi, I’m making a rotating turret for my game, and I want the turret to be controllable from the players mouse, but my code doesnt seem the work:

game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player, mouse)

	while wait() do
		gyro.CFrame = CFrame.new(part.Position ,Vector3.new(mouse.Hit.Position.X, part.Position.Y, mouse.Hit.Position.Z) )
	end

end)

I’m getting this error:
Hit is not a valid member of Vector3

I want the turret to follow the mouse position, I have done a lot of research, and all the posts I have found say to do mouse.Hit, but I’m getting said error, I’m not sure what to do.

Any help is much appreciated! :grinning: :+1:

You cannot pass the mouse to the server, because the limitation is due to possibly being non-replicated. Just send a Vector3 instead, passing Mouse.Hit.

I am already passing mouse.Hit from the client script:

Remote:FireServer(Mouse.Hit.Position)

Then the problem is in the code on the server. They’re supposed to be mouse.X and mouse.Z. You could rename the mouse argument into something like hitPosition.

I don’t know, maybe…

That’s why I’m asking for help…

Read it twice, you’re clearly not keeping track of the variables being sent across. Solution is provided above.

I’m sending the variables “player” and “mouse”.

I don’t see how you have provided a solution.

That doesnt work. I tried it.

You did not read it twice. I clearly pointed out that the passed argument mouse is a Vector3 already, and you need to change this line:

Vector3.new(mouse.Hit.Position.X, part.Position.Y, mouse.Hit.Position.Z)

…to this line…

Vector3.new(mouse.X, part.Position.Y, mouse.Z)

I already said in an above post…

There was no error? Be more specific. I cannot see what you have there.

Try using mouse.Hit.p

that will return a CFrame value
if you want to get a Vector3 then do

Vector3.new(mouse.Hit.p)

There’s no error in the output, but the part behaves strange… it will only follow the mouse once in every 10 seconds and its wiggling constantly and looks glitchy, I don’t have any recording software, so I’m not sure how I can show you…

I’m already using that, and it returns an error, as I have said in an above post…

Oh wait, I figured it out. The loop is causing problems here. You’re looping it for some reason. What’s the intended behavior?

1 Like

I want it to move seamlessly/constantly being controlled by the mouse.

How would I do that without it being glitchy?

I’m pretty sure you can do that kind of animation on the client instead. If this is on the server, why would it be on the server?

So it replicates to all players.

wait… i hope that script isnt on the server…?
right?
you cant pass a mouse onto the server…
the most you can do is pass the actual cframe value…

(through a remote event)

It is on the server and I’m passing through a remote and it works fine. I just need help with making the turret move seamlessly/constantly…

How would I do that?

You need to be more clear on this.
This is what the script is supposed to look like (assuming mouse is a vector3):

game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player, mouse)

	while wait() do
		gyro.CFrame = CFrame.new(part.Position ,Vector3.new(mouse.X, part.Position.Y, mouse.Z) )
	end

end)

now if that works, then what does the localscript look like?