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

How can I save the player's position in a datastore?

Asked by 4 years ago

I have a datastore system in my game that will save various player data like their money, health, their inventory, position, ect. I store each in a table in the datastore. I'm new to datastores, so I don't understand it entirely, but when I create another variable in the table for the position (which I don't actually use position, I use the humanoidrootpart's CFrame), it gives me the error:

104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.

I've tried this with both .Position and .CFrame, but I get the same error. Is there a workaround for this?

Here's the part of my script giving me trouble:

01local dataID = plr.UserId
02        local equipped = {}
03        local stored = {}
04        local playerStatus = {}
05        local equipCount = 0
06        local storedCount = 0
07        for i,v in pairs(plr.Character.Equipped:GetChildren()) do
08            equipCount = equipCount + 1
09            table.insert(equipped,equipCount,v.RealName.Value)
10        end
11        for i,v in pairs(plr.Inventory:GetChildren()) do
12            storedCount = storedCount + 1
13            table.insert(stored,storedCount,v.RealName.Value)
14        end
15        local data = {
View all 30 lines...

1 answer

Log in to vote
1
Answered by
thesit123 509 Moderation Voter
4 years ago

You could make Position a dictionary. or something..

01local data = {
02    Pounds = plr.Status.Pounds.Value,
03    Equipped = equipped,
04    Stored = stored,
05    Health = plr.Status.Health.Value,
06    Position = {
07        plr.Character.HumanoidRootPart.CFrame.X,
08        plr.Character.HumanoidRootPart.CFrame.Y,
09        plr.Character.HumanoidRootPart.CFrame.Z,
10    },
11}
0
Works like a charm. DejaSketch 84 — 4y
Ad

Answer this question