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