how do i set CFrames orientation?
i know i can use CFrame.Angles, but its glitchy so are there any different methods to set cframes orientation?
How is CFrame.Angles glitchy? Maybe you’re not converting the angle from degrees to radians?
i am, but sometimes it is reverting the orientation of a part
what i mean is this:
before leaving the game:
after a rejoin: (im using CFrame.Angles to save and load the orientation)
Try using CFrame.fromOrientation()
, it uses the same order as the orientation displayed in properties tab.
just tried that and this is what i got… maybe im using it the wrong way?
local scframe = CFrame.new(v.Middle.Position + Vector3.new(-g[2][1],g[2][2],-g[2][3])) * CFrame.fromOrientation(g[3][1],g[3][2],g[3][3])
structure.Parts:SetPrimaryPartCFrame(scframe)
Could I see the part where it loads and saves?
here is the entire script, its pretty basic. Dont mind PlotsDS, its a different data store that i am using to save something else. the one im having problems with is StructureDS
local PlotsDS = game:GetService("DataStoreService"):GetDataStore("Plots2")
local StructureDS = game:GetService("DataStoreService"):GetDataStore("Structures2")
local itemsmodule = require(game.ServerScriptService.ItemsModule)
game.Players.PlayerAdded:Connect(function(plr)
local plots = PlotsDS:GetAsync(plr.UserId)
local structures = StructureDS:GetAsync(plr.UserId)
local foundplot = false
local spawnpart
for i,v in pairs(workspace.Plots:GetChildren()) do
if v.Owner.Value == "No Owner" then
v.Owner.Value = plr.Name
spawnpart = v.SpawnPos
foundplot = true
for i,b in pairs(game.ServerStorage.BaseExpansions:FindFirstChild(v.Name):GetChildren()) do
if table.find(plots,b.Name) then
b.Parent = v.BaseParts
for i,c in pairs(b:GetChildren()) do
if c.Name == "BuildArea" then
c.Parent = v.BuildAreas
end
end
end
end
for i,g in pairs(structures) do
local structure = itemsmodule.ItemFromTable(plr,g[1])
structure.Parent = v.Structures
--local scframe = CFrame.new(v.Middle.Position + Vector3.new(-g[2][1],g[2][2],-g[2][3])) * CFrame.Angles(math.rad(g[3][1]),math.rad(g[3][2]),math.rad(g[3][3]))
local scframe = CFrame.new(v.Middle.Position + Vector3.new(-g[2][1],g[2][2],-g[2][3])) * CFrame.fromOrientation(g[3][1],g[3][2],g[3][3])
structure.Parts:SetPrimaryPartCFrame(scframe)
end
break
end
end
if foundplot == false then
plr:Kick("Sorry, The Server Is Full. Please Rejoin.")
end
plr.CharacterAdded:Connect(function(char)
char:SetPrimaryPartCFrame(spawnpart.CFrame)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local plots = {}
local structuretable = {}
local foundbase = false
for i,v in pairs(game.Workspace.Plots:GetChildren()) do
if v.Owner.Value == plr.Name then
v.Owner.Value = "No Owner"
for i,g in pairs(v.Structures:GetChildren()) do
local infotable = {}
local iteminfotable = itemsmodule.ItemToTable(g)
table.insert(infotable,iteminfotable)
local posX = -(g.Parts.PrimaryPart.Position.X - v.Middle.Position.X)
local posY = g.Parts.PrimaryPart.Position.Y - v.Middle.Position.Y
local posZ = -(g.Parts.PrimaryPart.Position.Z - v.Middle.Position.Z)
local vector3V2 = g.Parts.PrimaryPart.Orientation
table.insert(infotable,{posX,posY,posZ})
table.insert(infotable,{vector3V2.X,vector3V2.Y,vector3V2.Z})
table.insert(structuretable,infotable)
g:Destroy()
end
v.Structures:ClearAllChildren()
for i,b in pairs(v.BaseParts:GetChildren()) do
if b.Name ~= "BasePart1" then
table.insert(plots,b.Name)
b.Parent = game.ServerStorage.BaseExpansions:FindFirstChild(v.Name)
for i,c in pairs(v.BuildAreas:GetChildren()) do
if c.BaseNumber.Value == b.BaseNumber.Value then
c.Parent = b
end
end
end
end
foundbase = true
break
end
end
if foundbase == true then
local s,e = pcall(function()
PlotsDS:SetAsync(plr.UserId,plots)
end)
if s then
print("zapisano dzialki")
else
warn(e)
print("nie zapisano dzialek")
end
local s2,e2 = pcall(function()
StructureDS:SetAsync(plr.UserId,structuretable)
end)
if s2 then
print("zapisano struktury")
else
warn(e2)
print("nie zapisano struktur")
end
end
end)
I think the problem is just that the old saved rotations were messed up because you changed the loading method, try it with new placed blocks
i did already, but ill try again
nope, still looks like this.
Try saving using { PrimaryPart.CFrame:ToOrientation() }
instead of PrimaryPart.Orientation
this is what i got
ill try that, sounds promising
now theyre not appearing at all.
I don’t know what problem you are having here sorry.
What exactly are you saving? Never save the angles (XYZ). Save the matrix itself. The three vectors that make up the proper directions.
Then use CFrame.fromMatrix
to reconstruct it.