Ball wont throw

I made some scripts that supposed to shoot a ball out of a player’s mouse. Its a tool. But no ball is created when i click my mouse.

Local: Inside the tool

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local hit = mouse.Hit

local event = game.ReplicatedStorage.throw

local canshoot = true

local tool = script.Parent


function OnActivation()

if canshoot == true then
	canshoot = false
	print('Activation works')
	event:FireServer(hit)



	wait()
	canshoot = true

end
end


tool.Activated:Connect(OnActivation)

Server script: inside serverscript service

local storage = game.ReplicatedStorage

local event = storage.throw



local function onActivation(player, hit)


	
	local root = hit

	local ball = Instance.new("Part")
	ball.Shape = Enum.PartType.Ball
	ball.Color = Color3.new(0.133333, 0.133333, 0.133333)
	ball.Size = Vector3.new(2,2,2)
	ball.Material = Enum.Material.Grass
	ball.CanCollide = false

ball.Parent = game.Workspace
	local newCFrame = root
	local cf = ball.CFrame

	ball.CFrame = newCFrame


	local Velocity = Instance.new("BodyVelocity")

	Velocity.maxForce = Vector3.new(math.huge, math.huge, math.huge) 
	Velocity.Velocity = ball.CFrame.lookVector * 30


	Velocity.Parent = ball

end


event.OnServerEvent:Connect(onActivation)

There are no errors in the output.

activation works prints

Seems like you forgot to parent the ball to the workspace, or anything at all for that matter.

@Hxndaaa has the solution, but I’ll also suggest that you redefine hit in the LocalScript every time the tool is activated so that the client is sending the most up-to-date information about where the mouse is.

function OnActivation()

if canshoot == true then
	hit = mouse.Hit --Add this
	canshoot = false
	print('Activation works')
	event:FireServer(hit)



	wait()
	canshoot = true

end
end

Alright. Ye makes sense i missed that cause I was in a rush making the script. (I’m on mobile right now so I’ll get back to ya later and see if it works, probably will)

The ball shows now, and it moves, but it doesnt come out of the mouse, it just spawns at the origin.

I changed where mouse.hit was being defined, into the function and it worked. Thanks.