Shooting Object Forward while keeping Physics (Un-Anchored)

I’m making a script inside of a Hockey Stick Tool. I need to be able to, when clicked, shoot the puck in the direction of the player’s chest rotation. When the Puck is Touched, it will weld the puck to the Stick, then when it’s clicked, it will remove the puck and move it in a random direction. If the puck is shot at a wall, it will go through it, and if it’s shot into the net, it can’t detect it touching it.

This is my current Script

local enabled = false
-- 0, 0, -90
script.Parent.mid.Touched:Connect(function(hit)
	if hit.Name == "Puck" then
		if enabled == false then
			enabled = true
			print("hit puck")
			if hit:FindFirstChild("Weld") ~= nil then
				hit.Weld:Destroy()
			end
			local part = hit
			local weld = Instance.new("Weld", part)
			weld.Part0 = part
			weld.Part1 = script.Parent.mid
			weld.C0 = CFrame.new(0, -0.4, 0) *CFrame.new(0, -0.4, 0) -- Position your Part !
			weld.C0 = weld.C0 * CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
		end
	end
end)

script.Parent.Unequipped:Connect(function()
	if enabled == true then
		enabled = false
		game.Workspace:WaitForChild("Puck"):FindFirstChild("Weld"):Destroy()
	end
end)

script.Parent.Activated:Connect(function()
	if enabled == true then
		enabled = false
		game.Workspace:WaitForChild("Puck"):FindFirstChild("Weld"):Destroy()
	end
	for count = 1, 50 do
		if game.Workspace:WaitForChild("Puck"):FindFirstChild("Weld") == nil then
			local Part = game.Workspace:WaitForChild("Puck")
			Part.CFrame = Part.CFrame + Part.CFrame.lookVector * 1
			wait(0.0001)
		end
	end
end)

Any help is appreciated! Thanks :slight_smile:

Is this the part you are having trouble with?

What have you tried?

It is not clear what you are asking for in the post.

1 Like

Just my opinion, I would rather just set the velocity, because your puck might accidentally go at an angle and phase through the ground (or a net).

script.Parent.Activated:Connect(function()
   local Part = workspace:WaitForChild("Puck")
	if enabled == true then
		enabled = false
		Part:FindFirstChild("Weld"):Destroy()
	end
	Part.Velocity = Part.CFrame.LookVector * 50
end)

This is right just one thing, I put the Part Velocity inside the enabled, so you couldn’t shoot it with your Stick out, and not having the puck. The only problem is that sometimes when shooting it, it’ll get stuck to the Stick.

It’s most likely because you automatically assume that there is a weld, even when calling FindFirstChild().
Try this:

script.Parent.Activated:Connect(function()
   local Part = workspace:WaitForChild("Puck")
	if enabled == true then
		enabled = false
        local Weld = Part:FindFirstChild("Weld")
		if Weld then
           Weld:Destroy()
        end
	end
	Part.Velocity = Part.CFrame.LookVector * 50
end)