Im Gonna try explaining my issue withotu sending code cause that would just be a mess. I have a vfx beam ability that begins in front of the player and continuosly tracks the mouse position of the player who cast the ability and sets the end of the beam at the mouse position. The structure of my code goes like this, Client Detects Keypressed → FireServer → FireAllClients(ModuleScript) → Module Script Runs. My issue began when in 2 player mode, the player who did not cast the ability was not able to retreive the other players current mouse position through the module script and the error it gave me was attempt to index :GetMouse() with nil or something. I assumed this was because a client cannot retreive the mouse position of another client so I Decided to make it so that the player who casted the ability will continously FireAllClient the mouse position of their mouse to all the other clients. This fixed the problem untillll you try to have two seperate players that try to use the same ability at the same time. Both module scripts get confused about which mouse position to set the endpoint to and idk why. Im thinking that the solution would to make this a server sided script instead of having it run on the clients instead? Any solutions will help, If you feel like seeing the scripts ill send em over but its honestly a mess.
TLDR: How do most effectively you get the mouse position from one client to another client constantly.
I think you can still use the FireAllClients and keep it client sided but you will have to include the player variable when you pass it to clients so you can check it is from which player. But if you decide to make it server sided you can also use the player variable sent from FireServer to know which player it is from
1: client side will FireServer(mousepos)
2: server side receives plr, mousepos
3: server side fireallclients (plr, mousepos)
4: all client side receives plr and mousepos
5: check which player’s mousepos by using the plr variable
fire the event until the ability is over, using repeat task.wait() or runservice render step, for performance wise maybe you can check if the x and y value of the mouse changed before firing (firing only when it changes) you can limit how many times you want to fire the mousepos per second based on the task.wait(time in seconds). To add on, since youre going to replicate it to other client anyways you might as well have the ability script done on the server side so its not reduntant
1: client side will FireServer(mousepos)
2: server side receives plr, mousepos
3: server side fireallclients (plr, mousepos)
4: all client side receives plr and mousepos
5: check which player’s mousepos by using the plr variable
6: repeat step 1 until ability stops like below:
repeat task.wait()
fireserver(mousepos)
until ability stops
you can skip step 4 if you move the ability to be done on server side
This isn’t really a solution since @ifqksz has already said, but an improvement would be to send the scale position of the mouse instead of the actual position given by mouse.X and mouse.Y. You can do this by dividing it by the screen size which a camera obejct does
local mouseXScalePos = mouse.X/cam.ViewportSize.X
local mouseYScalePos = mouse.Y/cam.ViewportSize.Y
somethingremote:FireServer(mouseXScalePos, mouseYScalePos)
The reason why they’re seperate instead of one UDim2 or whatever is cause I don’t think you can pass stuff like UDim2s and stuff through remotes.
Also the reason for the scale is also cause everyone’s screens will be different sizes. So like a spell casted on the bottom right corner of a phone screen will still be the top left corner of a monitor screen.
So I’m doing the ability on the client side and I’m wondering how I would spawn the vfx only once and then get the part to move using the mouse position since the client is firing the script constantly?