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

How do you Store and Retrieve the CFrame Rotation of a Model Using DataStore?

Asked by 7 years ago

Introduction: I'm creating a system that requires me to save a models rotation and retrieve it once the player joins back. I've successfully uploaded, retrieved, and used accordingly all data about the model except it's rotation. I've been working on this for a few days, i'm finally ready to admit that I need help.

Question: How would I get the rotation of a model, store it on DataStore, and retreive it. I wish it was as easy as uploading the whole CFrame values - the position but you can't upload CFrame values to DataStore. I've tried converting the CFrame data to EulerAngles and reconverting to CFrame, it will upload the data but comes back as nil once i try to retreive it, even though it sucessfully uploaded the EulerAngles. I'm likely overthinking this.

Summary: I need to upload the rotation of a model to DataStore. I then need to be able to retrieve the data and set the models new rotation without altering the Model.Position (Vector3).

Side Question: To rotate models I've been setting the PrimaryPart's CFrame which does not automatically change the other parts of the model so i'm running each part through a Transform script I found on another forum, it's a little messy. If you have a good way to rotate a whole model, i will love you forever, in a non-weird way.

Things I've discovered: - In order to upload a table to a DataStore the keys have to be strings. - You can not directly store CFrame values to a DataStore - Model.PrimaryPart.CFrame - Model.PrimaryPart.Position= Returns Rotation Only

2 answers

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
7 years ago
Edited 7 years ago

First of all, I want you to love me forever. There is this awesome method called SetPrimaryPartCFrame. It allows you to set the CFrame of a single part within a model, and have all the other parts of the model adjust accordingly.

I don't see how you can be having troubles storing rotation. Just store the numbers of the CFrame? CFrame:components()

I googled the answer, and to my surprise, I answered it!

Note: I've still never had to do this myself, so I can't say that this solution is the absolute best solution, but it is a solution.

0
Yeah just use :components(). You don't even need the json stuff. cabbler 1942 — 7y
0
First of all, thanks for the help! These are the values of each windows65 2 — 7y
0
I posted an answer with the next problem windows65 2 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
These are my outputs for saving and loading. The value of :components() is being successfully transferred. The rotation values do not look correct though... And the models are not rotating. Suggestions?


**LOG:**
**----------------------------------------------------------**
Creating New Model...
Action---ListPos--Value
Saved: 1   -           -337.93368530273
Saved: 2   -          21.104787826538
Saved: 3   -          440.77005004883
Saved: 4   -          1
Saved: 5   -          0
Saved: 6   -          0
Saved: 7   -          0
Saved: 8   -          1
Saved: 9   -          0
Saved: 10   -        0
Saved: 11   -        0
Saved: 12   -        1
Colony Data Saved Sucessfully!


GENERATING Colony Item...
Loadd: 1   -           -337.93368530273
Loadd: 2   -          21.104787826538
Loadd: 3   -          440.77005004883
Loadd: 4   -          1
Loadd: 5   -          0
Loadd: 6   -          0
Loadd: 7   -          0
Loadd: 8   -          1
Loadd: 9   -          0
Loadd: 10   -        0
Loadd: 11   -        0
Loadd: 12   -        1
**----------------------------------------------------------**

Answer this question