Mouse.Hit.Position returning nil

My script needs to be ran on the server so i send a remote event to the client

–Server

local MouseP = game.ReplicatedStorage.MousePos:FireAllClients(MouseP)
print(MouseP)

–Client

game.ReplicatedStorage.MousePos.OnClientEvent:Connect(function()
	print(Mouse.Hit.Position)
	return(Mouse.Hit.Position)
end)

on the client it prints the position but on the server it prints nil

This is because the server has no mouse. Just send a client event using the same Remote Event with the mouses position.

1 Like

yea it sends request to the client to get the mouse then return it to the server

But you didn’t show the script that returns it to the server.

right there (filling space innnnn)

That only shows the client event. You cannot return a value from 2 separate scripts.

You cannot return a value with a RemoteEvent as they are a one-way communication. RemoteFunctions is what you need as it allows two-way communication.

But why are you trying to return the Mouse object from the client to the server? Why not return the Hit.Position instead? If you think this will protect it from exploiters, then I can assure you it won’t.

no its bc an npc needs to move from a players mouse pos and npc moves on server so it needs to send request from server to client to server

My bad. It seems I have misread your script. Then as I have mentioned, you need to use a RemoteFunction for this.

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