Best way to make a projectile that charges up and then is thrown in the direction of the mouse?

So here is the deal. I made an ‘energy ball’ spell where the user charges up an energy ball in their hand and then throws it in the direction of their cursor. The mouse location cannot be sent as soon as the power is activated because if the player moves their mouse while charging, the ball will go in the wrong place. The ball then explodes on impact, dealing damage to enemies in the blast radius.

So what would be the best way to get the player mouse from the server side? At first I was just using a remote function with InvokeClient but apparently you should never do that for some reason. I did have a safetynet where the server would keep track of players who are currently casting so the server cannot invoke the same client before the previous invokes are compete.

I then switched to a remote event where the server fires the client when the client should fire the server with current mouse position.

But this approach is messy. The server-side code to initiate the spell and launch the energy ball are no longer in the same function/same place.

So what approach would be recommended for this?

So wait, why wouldn’t the code to initiate and launch be in the same place?

Shouldn’t the function look like this?

RecieveEvent,SendEvent = nil,nil --don't actually set these to nil, lol.
function energyball(plr)
	task.wait(1)

	--//Request Info
	SendEvent:FireClient(plr)

	--//Recieve Info
	local WaitForResponse,Result
	WaitForResponse = RecieveEvent.OnServerEvent:Connect(function(Mouse))
		Result = Mouse
	end)
	--//Wait until client response. You may want to limit this from going indefinitely.
	repeat task.wait(0.025) until Result ~= nil

	--//Attack
end

Because making a new connection to OnServerEvent each time a player activates will cause problems if a different player (exploiter?) sends a (spoof?) server event after another player initiated but before the other player sent the real event.

By the way Player, Result = ReceiveEvent.OnServerEvent:Wait() is a cleaner way in my opinion than having a loop.

But using your idea I could have something like:

repeat
    Player, Result = ReceiveEvent.OnServerEvent:Wait()
until Player == plr

That would solve the issue I mentioned above.

Actually, remote events are forced to send the player object who fired them, exploits or not. I also forgot to account for that in the original code block I sent.

RecieveEvent,SendEvent = nil,nil --don't actually set these to nil, lol.
function energyball(plr)
	task.wait(1)

	--//Request Info
	SendEvent:FireClient(plr)

	--//Recieve Info
	local WaitForResponse,Result
	WaitForResponse = RecieveEvent.OnServerEvent:Connect(function(R_Player,Mouse))
		if R_Player ~= plr then return end --//Only the original player.
		Result = Mouse
	end)

	--//Wait until client response. You may want to limit this from going indefinitely.
	repeat task.wait(0.025) until Result ~= nil
	WaitForResponse:Disconnect() --//Clean up

	--//Attack
end