Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

CFrame.new not working as expected?

I'm trying to change a part's Position using CFrame.new but instead of the desired position it goes to 0, 0, 0. I've tried to fix it with using just Vector3.new() but still the same result.

local Event = game.ReplicatedStorage.LocalPlayer:WaitForChild("Place")
local Storage = game.ServerStorage

Event.OnServerEvent:Connect(function(X,PlaceItem, Pos, Ori)
	local Clone
	Clone = Storage.Placement[tostring(PlaceItem)]:Clone()
	Clone.Parent = workspace.PlacedItems
	Clone.Anchored = true

	-- New Position and Orientation
	Clone.CFrame = CFrame.new(Pos)
	Clone.CFrame = CFrame.Angles(0, math.rad(Ori), 0)
	
	
	print(tostring(Pos))
	print("Item Placed")
end)

Output:

-4, 0.5, 0  -  Server - PlacementService:16

1 answer

You should do the following:

Clone.CFrame = CFrame.new(Pos) * CFrame.Angles(0, math.rad(Ori), 0)

or

Clone.CFrame = CFrame.new(Pos, Vector3.new(0, math.rad(Ori), 0))

Because CFrame.Angles returns a CFrame with an empty position vector (0, 0, 0) with the desired rotation vector, that is why the position is 0, 0, 0.

This discussion is preserved as it was. New answers, comments, and votes are closed.