Throw object towards mouse position?

I’m working on a simple flashbang tool which is working completely fine. However, when it comes to throwing it I’ve come across some issues. I know how to throw a part relative to let’s say, where the player is facing, but how would I throw the flashbang depending on where the mouse is? So if the mouse was hovering over a player, it would fly in that direction.

Any help would be appreciated! :grinning:

Basically what you need to do is make a local script get the mouse position and fire a remote event and have the mouse in it like this; local player = game.Player.LocalPlayer local mouse = player:GetMouse() RemoteEvent:FireServer(mouse.hit.p)

2 Likes

Firstly, you can’t get mouse position from server, so you need to bind a function to a remotefunction that gets the mouse position, bind the .onclientinvoke of the remotefunction to a localscripts that gets the local players mouse using, an example of required code below
local Mouse = game.Players.LocalPlayer:Get mouse()
Then return the mouse cframe using
return Mouse.Hit
Your localscripts should look like this
local Remote = [Path to remote function]
local Mouse = game.Players.LocalPlayer:GetMouse()
Remote.OnClientInvoke = function()
return Mouse.Hit
end)

Finally, call this function in your server script when ever you need the mouse cframe
Remote = [Path to remotefunction]
function GetMouseCFrame(Player)
local Response = Remote:InvokeClient(Player)
return Response
end
Now that you have the Mouse Cframe, you can use the lookvector to launch the projectile in the mouse direction

Thanks for the help! I just had to pass it mouse.Hit.lookVector and use that value for the direction. Thanks so much! :grinning: