Making a grenade causes a problem

Hello, I am making a grenade, everything works properly, only a problem, I want the Z velocity to be set as mouse’s position’s Z-axis. Doesn’t work properly, here’s the code:

local Player = game.Players.LocalPlayer;

local Mouse = Player:GetMouse();

local ReplicatedStorage = game:GetService("ReplicatedStorage");

local Ball = ReplicatedStorage:WaitForChild("Ball")

local Character = Player.Character;

local debounce = false

local RightHand = Character:WaitForChild("RightHand")

Mouse.Button1Down:Connect(function()
    local newBall = Ball:Clone();
    newBall.Parent = game.Workspace;
    newBall.CFrame = RightHand.CFrame * CFrame.new(workspace.Camera.CFrame.LookVector) * CFrame.new(0, 0, -5)
    local gravity = 100
    
    local objectedSpace = workspace.Camera.CFrame:ToObjectSpace(Mouse.Hit)
    
    newBall.Velocity = newBall.CFrame * Vector3.new(0, gravity, -objectedSpace.X)
    
    newBall.Touched:Connect(function()
        if debounce == false then
            debounce = true
            local exp = Instance.new("Explosion", workspace)
            exp.Position = newBall.Position
            newBall:Destroy()
            wait(1)
            debounce = false
        end
    end)
end)
2 Likes

Why not use LookVector?

newBall.Velocity = mouse.Origin.LookVector * 50

Ok, let me test it, thank you mate

1 Like

it doesn’t work as intended any other solution?

Oh, I see you want more of a throwing movement, I’ll do that:

local directionalForce = 25
local upwardsMomentum = 100
local velocity = mouse.Origin.LookVector * directionalForce
newBall.Velocity = Vector.new(velocity.X, upwardsMomentum, velocity.Z)

Keep in mind, it’s not just the x or z, it’s the x and z combined that create forward direction.

Here’s a rough sketch:

What do you mean gravity.Z? I only have a number for gravity

I fixed that in my current edit.

Thanks, I am going to try this one.