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

Loading Tycoon data using data store?

Asked by
zblox164 531 Moderation Voter
5 years ago

I am working on the elements of a sandbox tycoon and still don't know how to load the players tycoon back into the game after leaving. I also will need to save it before they leave. One way I thought I could do it would be create a few values (bool value, int value, or Vector3Value) for each object that would store the position, and the key for that object (I mean like how many objects there were when you placed that object. Example: If there are 5 objects placed than it would have a key of 6) . My problem is when loading back in the data from a table. How would I create these values again that would match the data before. Also I would need to know how many objects the player had placed and which object type they were (What do I mean by type? Like is it a dropper or a decoration).

Here is one way I could do what I mean:

local Save = {}

local function Placement()
    -- Placment stuff

    -- EXAMPLE

    local PositionNRotation = Instance.new("CFrameValue")
    PositionNRotation
    PositionNRotation.Value = Object.PrimaryPart.CFrame

    table.Insert(SaveData, PositionNRotation.Value) -- This will error but you get the idea
end

placement()

local function SaveData(p)
    DataStore:SetAsync(p.UserId, Save)
end

local function LoadData(p)
    local SAVED 

    pcall(function(p)
        SAVED = DataStore:GetAsync(p.UserId)
    end)

    if SAVED then
        -- ???
    else
        -- ???
    end
end

game.Players.PlayerRemoving:Connect(SaveData)
game.Players.PlayerAdded:Connect(LoadData)

Hope this makes sence its hard to explain.

Thanks in advance for anyone who helps me!

Answer this question