Hello, I want to be able to save and load data like a game save.
The problem is, there is no set data like a obby or tycoon. All the elements that I need to save are changed by the player. (ex. Roller-coaster Tycoon, Store Tycoon)
The only thing that came to my mind is either, save every item the player has and where its located.
(I just need a general Idea on how to create this)
Edit: This is not like the examples above its a PC building type game so all the parts within the a PC (CPU, GPU) Need to be stored somehow I don’t know how to in a efficient way.
This is probably the best topic so far. You can get the CFrame of where it’s located, relative to the base of the tycoon. I would suggest storing these in tables.
In that case, you could use HttpService to JSONEncode it, then save it as a string. Once you want to fetch the data, get the string, and use HttpService to JSONDecode it.
Try this script and note that this will be in serverscriptservice.
local DataStoreService
game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)
local function onPlayerJoin(player) – Runs when players join
local leaderstats = Instance.new(“Folder”) --Sets up leaderstats folder
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local gold = Instance.new("IntValue") --Sets up value for leaderstats
gold.Name = "Gold"
gold.Parent = leaderstats
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
-- Data exists for this player
gold.Value = data
else
-- Data store is working, but no current data for this player
gold.Value = 0
end
end
local function onPlayerExit(player) --Runs when players exit
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Gold.Value) --Saves player data
end)
if not success then
warn('Could not save data!')
end