Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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

1RF = game.ReplicatedStorage.Remotes.GetMousePosition
2 
3RF.OnClientInvoke:connect(function()
4return(game.Players.LocalPlayer:GetMouse().Hit)
5end)

SERVER

1local GunRemote = game.ReplicatedStorage.Remotes.GunHandler
2 
3GunRemote.OnServerEvent:connect(function(plr, Action)
4if Action == "Shoot" then
5local mousehit = game.ReplicatedStorage.GetMousePosition:InvokeClient(plr)
6-- then make the project and stuff
7end)

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

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I'll show you how i did it

Server

1local GetMouse = replicatedStorage:WaitForChild("GetMouse")
2local mouse = GetMouse:InvokeClient(player)
3 
4mouse = 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

01local players = game:GetService("Players")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local player = players.LocalPlayer
04local mouse = player:GetMouse()
05local endp = nil
06 
07local GetMouseRequest = ReplicatedStorage:WaitForChild("GetMouse")
08 
09local function onGetMouseRequested(folder)
10    mouse.TargetFilter = folder
11    return mouse.hit.p
12end
13 
14GetMouseRequest.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

1local Event = replicatedStorage:WaitForChild("Event")
2 
3local function onMouseDown()
4    Event:FireServer(mouse.hit)
5end

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

1local Event = replicatedStorage:WaitForChild("Event")
2 
3local function onEventFired(player , mouse)
4print(mouse)
5end

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

0
Thanks so much, I got it to work! TayBoss76 22 — 7y
Ad

Answer this question