So I’m still working on my Placement System and I just can’t get this Rotate function right.
Here’s my code:
for _, part in pairs(PreviewModel:GetChildren()) do
local newOrientation = part.Orientation + Vector3.new(0, 90, 0)
part.Orientation = newOrientation
and here’s what happens:
I can rotate it, but when I move my mouse or try to place, it rotates back.
You only have rotated the part inside the PreviewModel, but anyways, I don’t know how your placement system works, so it’d be cool if you provide us with more information
When you place it, the wall’s information will be transferred to the server, including rotation.
that might be the problem, can you please show us the script, because the problem is in when you place the actual wall
It also resets when I move my mouse.
Here’s the code, nonetheless.
local Buildables = game.ReplicatedStorage.Buildables
function _PS:Place(playerName, build, position, rotation)
assert(Buildables:FindFirstChild(build) ~= nil, "Couldn't find Build in Buildables folder.")
local player = game.Players[playerName]
local Build = Buildables[build]:Clone()
Build.Parent = game.Workspace["Player Builds"]
Build.PrimaryPart.Orientation = rotation
change this: Build:SetPrimaryPartCFrame(CFrame.new(position)) to this:
CFrame.new(position) * CFrame.Angles(
That rotates it to be a floor.
i mean, you did already set the cframe to the preview’s cframe, I don’t see the needing of changing the orientation of it
since CFrame is position + orientation
Still resets it when I place, and when I move my mouse.
then it must be related to when you move your mouse, click it, can you show us that part of script too
Here’s when I update it (move my mouse):
if not IsBuilding then return end
if PreviewModel == nil then warn("Preview Model nil.") return end
CanPlace = not _PS:CheckForOtherBuilds()
local UnitRay = mouse.UnitRay
local Range = 30
local RayCast = Ray.new(UnitRay.Origin, UnitRay.Direction * 100)
local _, pos = workspace:FindPartOnRay(RayCast, PreviewModel)
and the placement just sends a remote event, which is then transferred through to the other script I sent you.
That’s the line, because it changes PreviewModel frame to pos.
Can you show us the script with
pos is determined above the line you’re looking at.
What’s the target of the Raycast? the Wall or the part inside the PreviewModel?
The target? I’m not too familiar with Rays. I set the UnitRay variable to the mouse.UnitRay property.
PreviewModel is handled through LocalScript or Script?
If it’s handled in Client, the server can’t see the rotation.
It’s on the client, but when placing, the server is told about the rotation, position, etc…
So you should try the most basic debbuging method, use
print(part.Orientation), in Server and Client. I also think you’re only changing the Orientation of PreviewModel, and not the “Model” itself.
I did it, and they’re lined up, but the actual build doesn’t rotate.
Also, I did try rotating the actual model. Didn’t work.
Well atleast now we know that this part is the cause of your orientation resetting because this is the only line of script that changes the preview model when you move or click.
somehow the pos is the previewmodel’s CFrame without the orientation, maybe it hit another part or something?