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

How to make a DataStore to save a parts position?

Asked by 6 years ago

I'm trying to make a datastore that saves the position of a part, how do I do this?

local DataStore = game:GetService("DataStoreService"):GetDataStore("DerrickPosition")
local Derrick = workspace:WaitForChild("Derrick")
game.Players.PlayerAdded:connect(function(plr)
    local uniquekey = "id"..plr.userId
    --LeaderStats
    local leaderstats = Instance.new("IntValue", plr)
    leaderstats.Name = "leaderstats"
    local Money = Instance.new("IntValue", leaderstats)
    Money.Name = "Money"
    --Saving
    local key = "user-"..plr.userId
    local saveValue = DataStore:GetAsync(key)

    if saveValue ~= nil then
        -- Save Format: {money, Position} Tables
        Money.Value = saveValue[1]
        Derrick.Position = saveValue[2]
    else
        local valueToSave = {Money.Value, Derrick.Position}
        DataStore:SetAsync(key, valueToSave)
    end
end)
game.Players.PlayerRemoving:connect(function(plr)
    local key = "user-"..plr.userId
    local valueToSave = {plr.leaderstats.Money.Value, Derrick.Position}
    DataStore:SetAsync(key, valueToSave)
end)

0
You haven't tried to save it, so don't expect any scripts. H4X0MSYT 536 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

YOU CANNOT STORE "userdata" VALUES (Vector3, Udim2, Faces, Color3, etc) use an lua "table" instead:


-- Replace all "Derrick.Position"s to: {X=Derrick.Position.X,Y=Derrick.Position.Y,Z=Derrick.Position.Z} -- and if you ever require referencing certain values: tablenamehere[X] tablenamehere[Y] tablenamehere[Z]
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

Just save the position of the part....? Either that or your question needs more detail.

0
You can't save Vector3 values. Fsxfighter265 10 — 6y
0
Save the co-ordinates in a table... You really have noidea how to script I would think. TABLES ARE A MANS BEST FRIEND. H4X0MSYT 536 — 6y

Answer this question