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 6 years ago
Edited 6 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

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

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

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

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

Answer this question