Throwing grenade won't work

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.

1 Like

https://developer.roblox.com/en-us/api-reference/property/BasePart/Velocity

The item is deprecated. I suggest you use another alternative.

Thanks let me look into this post

A BasePart’s “Velocity” property is described by a Vector3 value not a CFrame value.

    local t = 1;
    local hrp = Thrower:WaitForChild("HumanoidRootPart");
    
    local g = Vector3.new(0, -Workspace.Gravity, 0);
    local x0 = hrp.CFrame * Vector3.new(0, 2, -2)

    local v0 = (MouseHit - x0 - 0.5*g*t*t)/t;


    grenade.Velocity = v0;
    grenade.CFrame = CFrame.new(x0);

Right now im using this but it doesn’t work it gives me this error:
image

1 Like

Which line is specifically causing the issue?

It says line 55, so

local v0 = (MouseHit - x0 - 0.5*g*t*t)/t;

Make sure MouseHit is Mouse.Hit/Mouse.Hit.Position and not the mouse object itself.

Yes it is, MouseHit is Mouse.Hit.Position. It comes from a clientscript that got fired in a remote event