Why is Mouse.Hit not working?

So the context is, that I was trying to get Mouse.Hit and put it in a CFrameValue every time that a player’s mouse is moved. But every time I ran the script it would give this error.
image

I’m still trying to understand why it won’t work. Here are the scripts:

LocalScript:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.Move:Connect(function()
	
task.wait()
print("Yeepie it works!")

local MousePos = Mouse.Hit


script.MousePosition:FireServer(Mouse, MousePos)

	
end)

ServerScript:

script.Parent.OnServerEvent:Connect(function(Mouse, MousePos)
	local CFrameVal = script.Parent.CurrentMousePosition
	
	CFrameVal.Value = MousePos
	print(CFrameVal) --checking if it works
	
end)

Any help is appreciated!

1 Like

You never added an end here.

Mouse.Move:Connect(function()

end)
1 Like

But I did though otherwise the script wouldn’t have run and given me the initial error.

1 Like

Can you try running print(Mouse.Hit) in the LocalScript?

2 Likes

When you’re firing the remote you sent the mouse and the mouse position as a parameter.

Fix:
Replace in Local Script, where you’re firing the remote:

script.MousePosition:FireServer(MousePos)

Replace in ServerScript

script.Parent.OnServerEvent:Connect(function(Player, MousePos)
	local CFrameVal = script.Parent.CurrentMousePosition
	
	CFrameVal.Value = MousePos
	print(CFrameVal) --checking if it works
	
end)
2 Likes

In the LocalScript it printed it as expected but in the ServerScript it gave me a nil

Do what @killermurderator said, I didn’t notice you had the parameters wrong on the remote event, remember that the first parameter to the function when responding in a server script will always be the player.

2 Likes

This solved the issue! Thank you so much, I’ve been trying to fix this for hours.

1 Like

It worked! I also didn’t notice, I always get parameters confused. Thank you!

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