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

How do i fix my rotation datastore glitch??

Asked by 4 years ago

Hey Guys so i have a placement datastore and stuff And R To rotate by 90 Degrees but. Whenever you rejoin it saves the placement but it does not save your rotation when you rejoin it rotates by 90 degrees and then you rejoin again it rotates by 180 degrees and keep on adding 90 degrees to it Here is the script.

local players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DatBaseV2")



local function GetPlot(plr)
    for i, plt in pairs(workspace.Plots:GetChildren()) do
  if plt then
   if plt.Plot.Owner.Value == plr then

return  workspace.Plots:FindFirstChild(plt.Name)

   end
  end
 end

end


local function Save(plr)
        local key = "plr-"..plr.UserId
        wait(0.1)
        local plot = GetPlot(plr)
        local save = {}

        for i, obj in pairs(plot.PlacedObjects:GetChildren()) do
            if obj then
                table.insert(save, {
                    ["Name"] = obj.Name,

                    ["CFS"] = {
                        ["X"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).X;
                        ["Y"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Y;
                        ["Z"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Z;

                        ["R"] = obj.PrimaryPart.Orientation.Y

                    }
                })
            end
        end


        local success, err = pcall(function()
            DataStore:SetAsync(key, save)
        end)

        if not success then
        warn("Failed to over-write data( "..tostring(err))
        return
        end
end


local function Load(plr)
    wait(1)

local plot = GetPlot(plr)
    local key = "plr-"..plr.UserId

    local savedData

    local success, err = pcall(function()
        savedData = DataStore:GetAsync(key)
    end)

    if not success then
        warn("Failed to read data( "..tostring(err))
        return
        end
        if savedData then
            for i, data in pairs(savedData) do
                if data then
                    local SaveModel = game.ReplicatedStorage.Models:FindFirstChild(data.Name):Clone()

                    if SaveModel then
                        SaveModel.PrimaryPart.Transparency = 1

                        SaveModel:SetPrimaryPartCFrame(plot.Plot.CFrame * CFrame.new(data.CFS.X,data.CFS.Y,data.CFS.Z) * CFrame.Angles(0,math.rad(data.CFS.R), 0) )

                    SaveModel.Parent = plot.PlacedObjects
                    end
                end
            end
        else
            Save(plr)
        end

end
game.ReplicatedStorage.Events.Save.OnServerEvent:Connect(Save)


players.PlayerAdded:Connect(Load)
players.PlayerRemoving:Connect(Save)
0
when you multiply by angles you're adding angles on top of the current angle royaltoe 5144 — 4y
0
then you're saving the current angle, adding to that angle, every time you load etc. royaltoe 5144 — 4y
0
How would i fix that? Cause my friend made the uhm datastore cause i am not good with Math scripting And Tables. Corrupt_Wolfstrik3r 51 — 4y
0
Like idk how to fix it that is why i am asking like how will i fix it as in a example? Or a link to a video or Something to teach me how to fix it. Corrupt_Wolfstrik3r 51 — 4y
View all comments (7 more)
0
Don't multiply it by angles unless you want to change the Cframe. just set the cframe to the previously saved cframe. royaltoe 5144 — 4y
0
I have a lab I'll be back in an hour if you need more help royaltoe 5144 — 4y
0
I Think i do i kinda know what you mean but i wanna be 100% Sure Cause i am still not 100% sure on what to do. Corrupt_Wolfstrik3r 51 — 4y
0
Yeah idk how i try'd XD! Corrupt_Wolfstrik3r 51 — 4y
0
What did you try royaltoe 5144 — 4y
0
Try'd / and + - .. , and all of that. Corrupt_Wolfstrik3r 51 — 4y
0
i mean what code did you write and please comment in my answer I can't see your comments in my notifications otherwise royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

EDIT: Try this:

SaveModel:SetPrimaryPartCFrame(CFrame.new(data.CFS.X,data.CFS.Y,data.CFS.Z) * CFrame.Angles(0,math.rad(data.CFS.R), 0) )
0
This is the script. Corrupt_Wolfstrik3r 51 — 4y
0
What do i use besides Angles? Corrupt_Wolfstrik3r 51 — 4y
0
SaveModel:SetPrimaryPartCFrame(whatever the cframe you saved in the datastore was) royaltoe 5144 — 4y
0
You alright? royaltoe 5144 — 4y
View all comments (5 more)
0
I still have no clue. Corrupt_Wolfstrik3r 51 — 4y
0
Could you please try to explain what you're confused on royaltoe 5144 — 4y
0
Like on what do you mean? Corrupt_Wolfstrik3r 51 — 4y
0
SaveModel:SetPrimaryPartCFrame(CFrame.new(data.CFS.X,data.CFS.Y,data.CFS.Z) * CFrame.Angles(0,math.rad(data.CFS.R), 0) ) royaltoe 5144 — 4y
0
That should work ^^ royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

So what do i use?

Answer this question