Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I send the Mouse.Hit of a PlayerMouse to the server from the client on FE?

I need a way to send/receive the Mouse.hit property of the PlayerMouse to the server for filtering enabled purposes. I have tried before by using InvokeClient in a RemoteFunction to return the mouse.Hit but it returned nil. Here is what I did (I KNOW THERE ARE TYPOS I WROTE THIS UP ON SPOT AS AN EXAMPLE)

----Using InvokeClient-----

CLIENT

RF = game.ReplicatedStorage.Remotes.GetMousePosition

RF.OnClientInvoke:connect(function()
return(game.Players.LocalPlayer:GetMouse().Hit)
end)

SERVER

local GunRemote = game.ReplicatedStorage.Remotes.GunHandler

GunRemote.OnServerEvent:connect(function(plr, Action)
if Action == "Shoot" then
local mousehit = game.ReplicatedStorage.GetMousePosition:InvokeClient(plr)
-- then make the project and stuff
end)

I really need help please if you know how to do this/fix what I did then please reply.

1 answer

✓ Accepted answer

I'll show you how i did it

Server

			local GetMouse = replicatedStorage:WaitForChild("GetMouse")
			local mouse = GetMouse:InvokeClient(player)	

			mouse = GetMouse:InvokeClient(player, folder) -- The folder is just what i parent everything to so i can use it later to make it ignore all the objects i need to be ignored

Client

local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer
local mouse = player:GetMouse() 
local endp = nil

local GetMouseRequest = ReplicatedStorage:WaitForChild("GetMouse")

local function onGetMouseRequested(folder) 
	mouse.TargetFilter = folder
	return mouse.hit.p
end

GetMouseRequest.OnClientInvoke = onGetMouseRequested

I use this method only when I need to constantly update the position of the mouse, the easiest way to do it without updating the mouse is really simple

Wherever you're firing your Remote Function

local Event = replicatedStorage:WaitForChild("Event")

local function onMouseDown()
	Event:FireServer(mouse.hit)
end

And in case you don't know how to get the mouse.hit from that you can do

local Event = replicatedStorage:WaitForChild("Event")

local function onEventFired(player , mouse)
print(mouse)
end

This sends the mouses position from client to server once and doesn't update the position, so good only if you need it once

Hopefully you'll be able to figure this all out

1 comment

0

Thanks so much, I got it to work!

This discussion is preserved as it was. New answers, comments, and votes are closed.