Y can not be assigned to error

Hi i have a problem with a script so i want the Y axis of a part to look at a other parts Y axis? but i get the error Y can not be assigned to?

script:

local Target = game.Workspace:WaitForChild("Target")

local Runservice = game:GetService("RunService")

Runservice.Heartbeat:Connect(function()
	script.Parent.Orientation.Y = Target.Orientation.Y
end)

Why is this error happening?

Orientation is a Vector3 and the individual X, Y and Z fields are read-only meaning you can’t assign values to them like that

1 Like

is there a vector 1 or smth? to fix this issue

Vector3 has readable properties, but not writeable. You’ll have to replace it with a new Vector3 copy with the new properties.

1 Like

Wait is there a way to use Lookat but only with the Y axis?

This error is occurring because The “Y” is a sub-category of a part’s rotation and therefore is read only. Instead, you need to update the whole position. Try this script:

〃〃〃lua
local Target = game.Workspace:WaitForChild(“Target”)

local Runservice = game:GetService(“RunService”)

Runservice.Heartbeat:Connect(function()
script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X, Target.Orientation.Y, script.Parent.Orientation.Z)

end)

〃〃〃

1 Like

Thank you! but how could I maybe like use lookvector but only y axis?

I’ve never heard of lookvector. Let me do a little research and i’ll get back to you! :grinning:

1 Like

Alright, so just to clarify, you want a part to “look” at another part but only on the y axis?

1 Like

Yes i really need that rn, (i have to put this part cuz of limit :smiley:)

Alrighty. I’m going to test a couple things in studio real quick and send a reply shortly. :+1:

1 Like

Alright thanks, By the way no rush!

This will take more work than I thought, so i will hopefully get this to you sometime tonight.

1 Like

Ok try this!

local target = game.Workspace:WaitForChild("Target")
local runservice = game:GetService("RunService")

function CFrameToOrientation(cf: CFrame)
	local rx, ry, rz = cf:ToOrientation()
	return Vector3.new(math.deg(rx), math.deg(ry), math.deg(rz))
end

runservice.Heartbeat:Connect(function()
	local lookatCFrame = CFrame.lookAt(script.Parent.Position, target.Position)
	
	local y = CFrameToOrientation(lookatCFrame).Y
	

	script.Parent.Orientation =  Vector3.new(script.Parent.Orientation.X, y, script.Parent.Orientation.Z)
	
end)

This will make the script’s parent face the target for only the Y axis.
Hope it helps! :partying_face:

1 Like

maybe try this since u cant set individual values for orientation

local Target = game.Workspace:WaitForChild("Target")

local Runservice = game:GetService("RunService")

Runservice.Heartbeat:Connect(function()
	script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X , Target.Orientation.Y, script.Parent.Orientation.Z)
end)
1 Like

Thank you all for helping! (30 letters limit)

1 Like

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