Hello, i’m trying to make a grenade script that fires a RemoteEvent from the client to the server with the mouse’s position on the screen.
When i do this the remote event connects to the script but then the grenade just dissapears (it is supossed to go to the mouse’s position). I check the server to see where it went and then it just flies very fast across the other side of the map. (So basically what i am doing is i’m trying to make it go up and then go down to the enemy where the mouse position is.)
This is the code it uses Velocity:
local handlePos = Vector3.new(Tool.Handle.Position.X, 0, Tool.Handle.Position.Z)
local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z)
local distance = (handlePos - mousePos).magnitude
local altitude = mousePosition.Y - Tool.Handle.Position.Y
local angle = AngleOfReach(distance, altitude, Config.GrenadeVelocity.Value)
Tool.Handle.Transparency = 1
local grenade = Tool.Handle:Clone()
grenade.Parent = workspace
grenade.Transparency = 0
grenade.CanCollide = true
grenade.CFrame = Tool.Handle.CFrame
grenade.Velocity = CFrame.new(grenade.Position, Vector3.new(mousePosition.X, grenade.Position.Y, mousePosition.Z)) * CFrame.Angles(angle, 0, 0).LookVector * Config.GrenadeVelocity.Value
If anyone sees the problem in the velocity please let me know. It would be very helpfull i can’t get to see what the problem is. Thanks.