I made this turret script however the turret head goes off of the body


local Tween = TS:Create(self.Char.PrimaryPart, Info, {CFrame = CFrame.new(self.Char.PrimaryPart.Position, Vector3.new(Target.Parent.PrimaryPart.Position.X,self.Char.PrimaryPart.Position.Y ,Target.Parent.PrimaryPart.Position.Z)) })
1 Like

Try to use CFrame.LookAt() . CFrame.new(Origin,LookTo) is deprecated. As this document says CFrame.new(position,lookat) constructor deprecated, replace with alternative accepting upvector - #3 by sjr04

Same Problem, its a problem with the way it rotates. I have to add an offset but idk how.

Can i see the full script perhaps?

local function Attack(Target, self)
	if not Target then return end
	--Fire Gun 
	-- Pew pew
	-- Account for reload and stuff, idk
	--- Ehh 
	local Tween = TS:Create(self.Char.PrimaryPart, Info, {CFrame = CFrame.lookAt(self.Char.PrimaryPart.Position, Vector3.new(Target.Parent.PrimaryPart.Position.X,self.Char.PrimaryPart.Position.Y ,Target.Parent.PrimaryPart.Position.Z)) })
	if  Target.Parent:FindFirstChild("Humanoid") then
		local Hum = Target.Parent:FindFirstChild("Humanoid")

function BotFunctions.New(Char)
	local self = setmetatable({ }, BotFunctions)
	self.Char = Char
	self.Attacking = false
	return self

function BotFunctions:StartLooking()
	while wait(1) do
		local Hit = FindPlayers(self.Char)
		if Hit then
			if Hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Hit.Parent) then
				Attack(Hit, self)
				self.Attacking = true

You need to center it somehow.

It’s centered from here. Try to center it from where you want it to be.

I’m thinking its because your turret is one union, and its center from the center of the volume. Try to add another invisible brick, and then weld the turret to its center.

1 Like

Try Printing the Position of both the turret and the base.
I’m not much of a scripter, but I’m guessing that you could figure out the offset by just placing a Cylindrical Part in line with the center of the turret top (have the turret centered on the X axis), and then be able to calculate the difference there.
Example: turret top is at 0,4,0 but cylinder is at 2.392,4,0 then you know the offset is 2.392
Also you should be locating the turret at the center (X,Z) of the base’s Position, not the center of the turret’s Position.


I like easy solutions, so instead of adjusting the script, I would adjust the model.

what is happening is that your turret is a model with a center.
this script rotates that model around that center.

if you move that center by placing a block without collision and transparency=1 on the opposite side of the turret the center will be more pushed towards the base, it does take some fiddling

1 Like