im trying to make it so a turret stops following the mouse at a certain point
when it does it spins
video:
https://streamable.com/k7e79g
code:
aimpos = mouse.Hit.p if gun.gun.base.Orientation.y >= 105 and dontmove == false then gun.gun.base.Orientation = Vector3.new(gun.gun.base.Orientation.x,104,gun.gun.base.Orientation.z) dontmove = true end if gun.gun.base.Orientation.y <= 77 and dontmove == false then gun.gun.base.Orientation = Vector3.new(gun.gun.base.Orientation.x,78,gun.gun.base.Orientation.z) dontmove = true end if gun.gun.base.Orientation.y <= 104 and gun.gun.base.Orientation.y >= 78 and dontmove == true then dontmove = false end if (aimpos-gun.base.Position).magnitude>3 and dontmove == false then local c = aimpos local x = (gun.gun:GetPrimaryPartCFrame()*CFrame.new(0, 0, -20)).x local y = SPAWN.y local z = (gun.gun:GetPrimaryPartCFrame()*CFrame.new(0, 0, -20)).z A = Vector3.new(x, y, z ) if c then gun.gun:SetPrimaryPartCFrame( CFrame.new(gun.body:GetPrimaryPartCFrame().p,Vector3.new(c.x, -20, c.z)) ) gun.body:SetPrimaryPartCFrame( CFrame.new( SPAWN.p, A ) ) else gun:SetPrimaryPartCFrame(gun.body:GetPrimaryPartCFrame()) gun.body:SetPrimaryPartCFrame( CFrame.new( SPAWN.p, A ) ) end end