X cannot be assigned to CFrame Error

Hi other developers,
I’ve been lately running into this issue where I can’t set the CFrame of a new Clone of an object from replicated storage to the mouse’s CFrame.
Im currently attempting to create a placing system kind of like the one in a tds game.

This is my code:

local function CreateTurret(TurretID)
	if TurretID == 1 then
		
		local NewTurret = Turrets.TurretFirst:Clone()
		NewTurret.Parent = NewTurretFolder
		
		while true do
			local TurretBasePart = NewTurret:WaitForChild("TurretBasePart")
			TurretBasePart.CFrame.X = PlayerMouse.Hit.X
			TurretBasePart.CFrame.Y = PlayerMouse.Hit.Y
			task.wait()
		end

	end
end

Thank you!

CFrame.X / Position.X, Y or Z is Read Only, so you will instead have to use CFrame.new() or Vector3.new().

TurretBasePart.CFrame = CFrame.new(PlayerMouse.Hit.X, PlayerMouse.Hit.Y)
1 Like

Hi There StarJ3M, I’ve done what you said but now I have a error that says:
invalid argument #1 to ‘new’ (Vector3 expected, got number)
And then when I change it to a vector3 it gives me the error of CFrame expected

oh nvm I found the solution, I just didn’t add in the third value for CFrame

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.