Unexpected Behavior with Part Placement System

Essentially, I want this part to remain at a constant orientation of (0,0,0) while it is moving, however; it is always tilted to the side right now.

fjdsuafjadspfoijads

I’m not quite sure how to fix this, because it’s something I haven’t ever really tampered with before - but here’s the current code (only using RunService for testing purposes):

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.TargetFilter = game.Workspace.MainPart
local TweenService = game:GetService("TweenService")

game:GetService("RunService").RenderStepped:Connect(function()
	local ray = Ray.new(Mouse.Hit.p, Vector3.new(0,-25,0))
	local part, pos, normal = workspace:FindPartOnRayWithIgnoreList(ray, {game.Workspace.MainPart, workspace.CurrentCamera})
	if not part then
		local Tween = TweenService:Create(game.Workspace.MainPart, TweenInfo.new(.2, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false, 0), {CFrame = Mouse.Hit, Orientation = Vector3.new(0,0,0)}):Play()
	end
end)

Any help is appreciated, thanks!

The problem here is that tables with string indices have no order. Even though you specified Orientation after CFrame, TweenService may receive Orientation first when iterating over the table, causing CFrame to override it after-the-fact. You’ll need to manually convert your CFrame to have no rotation. You can do this by using:

{CFrame = CFrame.new(Mouse.Hit.p)}

This will place it at the target position with an orientation of 0,0,0. You can modify the orientation by multipling the CFrame by Angles e.g.

{CFrame = CFrame.new(Mouse.Hit.p) * CFrame.Angles(0,math.pi/2,0)}
4 Likes