Still have questions? Join our Discord server and get real time help.
0

# Why does this make the part go into the distance instead of where I specified it?

This script basically makes a barrel of a gun(for a tank) to point in the target's position(which is mouse.Hit.p). However, instead of locking onto the tank and pointing where it should, it just disappears. Help?

function move(target)
if script.Parent.Parent:findFirstChild("Barrel") then
local mp = barrel
local dir = (target - mp.Position).unit
local pos = mp.Position + (dir*1)
if engine:FindFirstChild("WeldBarrel") then
local wb = engine.WeldBarrel
wb.C0 = CFrame.new(pos, pos + dir) -- this is supposed to make the barrel point towards the mouse, but it just teleports off into the distance.
end
end
end