Mouse.Hit.Position returning the player instance

I have been trying to make a client script send the Mouse.Hit.Position value to a ServerScript using a RemoteEvent, however, whenever I fire the remote event and send the value, on the serverside it turns out as the player instance, which causes an error. Is there any solution to this?

I’ve been trying for multiple hours now to find the solution but I can’t.

LocalScript:

wait(1)

local plr = game.Players.LocalPlayer
while true do
	local mouse = plr:GetMouse()
	local pos = mouse.Hit.Position
	print(pos)
	script.Parent.ChangeMousePos:FireServer(pos)
	wait()
end

ServerScript:

script.Parent.ChangeMousePos.OnServerEvent:Connect(function(mouse)
	mousePos = mouse
	print(mouse)
end)

LocalScript Output:
(Mouse Vector3 Value)
image

ServerScript Output:
(Player Instance)
image

It doesn’t turn into a player, when you use OnServerEvent the first parameter is the player and the rest are the ones that you put, so the server-sided script should look like this:

script.Parent.ChangeMousePos.OnServerEvent:Connect(function(player, mouse)
	mousePos = mouse
	print(mouse)
end)

Hopefully helps!

I’ll try it out, thank you for telling me.

It still seems to be the player instance, it’s printing out the player as the second variable
image

I’m not sure if I’m doing anything wrong or what.

That’s actually weird, try printing the first and second parameter and also, can you send me the new version of the script?

image
It seems that both of the variables are the player, even though I’m not setting the second one to the player, but the Mouse.Hit.Position.

LocalScript
image

That’s not what I meant you should do, you don’t need to change anything on the LocalScript just change the Server script to what I sent to you

It’s working now, thank you for telling me about the first parameter being the player, I wouldn’t have ever found the solution if it wasn’t for you.

1 Like