Hey everyone! So I have a plot placement system however when I run the code that you see below, it is not on the plot. It is on the side of the plot. Why does this happen? Thanks
local newCFrame = Clone.CFrame:ToWorldSpace(game.Workspace.HomeArea.Plots[player.PlotOwner.Value].CFrame)
This post can explain it better than I can. I cannot say if it will definitely fix it, however it answers the title of the post. This function sets a CFrame relative to another CFrame - hopefully that’s of some help?
What are your inputs, and what is your desired outcome?
I have no idea what the image you posted is supposed to look like. There’s just two brown rectangles on the screen and you say “it’s diagonal”—what does that mean?
Ok so let me explain. I have a data store that when you leave, it saves all the parts on you previous part. It save it through cframes. The only issue is when you are on a new plot they are loaded on your previous plot. I tried to save it through ToObjectSpace but the image I displayed above was the outcome. I don’t know why though since I think I did everything correctly.
-- figure out what cframe to store:
local relative = Plot.CFrame:ToObjectSpace(ObjectToSaveCFrame)
Then you’d want to store relative.
(2) is also easy:
-- figure out what cframe to place at (once we load the above)
local whereItShouldGo = NewPlot.CFrame:ToWorldSpace(ObjectWeLoadedCFrame)
-- or just NewPlot.CFrame * ObjectWeLoadedCFrame (it's the same thing)
Most of my projects are related to placement systems what i would do is save the Objects Primary Part CFrame into Datastores and use SetPrimaryPartCFrame() or the new PivotTo() to move the object relatively to the plot
local function findOpenPlot(player)
repeat wait()
until player.Character
for i, plot in pairs(plotsFolder:GetChildren()) do
if plot.Owner.Value == "" then
if not player:FindFirstChild("PlotOwner") then
plot.Owner.Value = player.Name
local PlotOwner = Instance.new("StringValue")
PlotOwner.Value = plot.Name
PlotOwner.Name = "PlotOwner"
PlotOwner.Parent = player
player.OwnedPlot.Value = plot.Name
plot.NamePart.NameTag.SurfaceGui.TextLabel.Text = player.Name
player.Character.HumanoidRootPart.CFrame = plot.CFrame + Vector3.new(0,10,0)
end
end
end
local data = PlotsDataStore:GetAsync(player.UserId.."_PlotStuff")
if data then
for i, v in pairs(data) do
if game.ReplicatedStorage.Parts:FindFirstChild(v) then
local Clone = game.ReplicatedStorage.Parts[v]:Clone()
Clone.BasePart.Transparency = 1
if Clone:FindFirstChild("PartFound") then
Clone.PartFound.Value = false
end
local Split = string.split(data[i+1], ",")
--Clone.CFrame = CFrame.new(Split[1],Split[2],Split[3],Split[4],Split[5],Split[6],Split[7],Split[8],Split[9],Split[10],Split[11],Split[12])
--local newCFrame = Clone.CFrame:ToObjectSpace(game.Workspace.HomeArea.Plots[player.OwnedPlot.Value].CFrame)
Clone.CFrame = game.Workspace.HomeArea.Plots[player.OwnedPlot.Value].CFrame:ToWorldSpace(CFrame.new(Split[1],1.2,Split[3],Split[4],Split[5],Split[6],Split[7],Split[8],Split[9],Split[10],Split[11],Split[12]))
Clone.BasePart.CFrame = Clone.CFrame - Vector3.new(0,0.2,0)
--Clone.Position = Vector3.new(tonumber(data[i+1]), 1.2, tonumber(data[i+3]))
--Clone.BasePart.Position = Vector3.new(tonumber(data[i+1]), 1, tonumber(data[i+3]))
Clone.Parent = game.Workspace.HomeArea.Plots[player.OwnedPlot.Value]
--print(Clone.CFrame)
end
end
end
end
local DataStoreService = game:GetService("DataStoreService")
local PlotsDataStore = DataStoreService:GetDataStore("Plots")
local function savePlotData(player)
local OwnedPlot = game.Workspace.HomeArea.Plots[player.PlotOwner.Value]
local PlotStuff = {}
for i, part in pairs(OwnedPlot:GetChildren()) do
if part.Name ~= "Owner" and part.Name ~= "Border" and part.Name ~= "NamePart" then
table.insert(PlotStuff, part.Name)
table.insert(PlotStuff, tostring(part.CFrame:ToObjectSpace(game.Workspace.HomeArea.Plots[player.OwnedPlot.Value].CFrame)))
--table.insert(PlotStuff, tostring(part.CFrame.Y:ToObjectSpace(game.Workspace.HomeArea.Plots[player.OwnedPlot.Value])))
--table.insert(PlotStuff, tostring(part.CFrame.Z:ToObjectSpace(game.Workspace.HomeArea.Plots[player.OwnedPlot.Value])))
end
end
local encoding = HttpService:JSONEncode(PlotStuff)
wait(1)
local decoding = HttpService:JSONDecode(encoding)
local success, err = pcall(function()
PlotsDataStore:SetAsync(player.UserId.."_PlotStuff",decoding)
end)
if err then
warn(err)
end
end