Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

CFrame.new not working as expected?

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago

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.

Ad

Answer this question