How do I save my game while in game?

Hey Guys,
The title probably makes no sense so here’s what I mean. Any help, forum pages or tutorials would be great.
How can I setup a system that saves my game with all the builds I have made using building tools in my game?

Thanks, Soli

You can just use DataStoreService or another data saving api to save your builds. In the example code, you can parent the player’s builds to a model and save that using DataStoreService. Then, when a player joins, you can load in the model and unpack it.

local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("PlayerBuilds")

game.Players.PlayerAdded:Connect(function(player)
	local buildsModel
	local success, err = pcall(function()
		buildsModel = datastore:GetAsync("Player_"..tostring(player.UserId))
	end)
	if err then warn(err) end
	
	-- Unpack the model and do stuff with the builds
end)

game.Players.PlayerRemoving:Connect(function(player)
	local model = Instance.new("Model")
	-- Parent the builds to the model
	local success, err = pcall(function()
		datastore:SetAsync("Player_"..tostring(player.UserId), model)
	end)
	if err then warn(err) end
end)

With like the tool building tool thats with most admin panels like HD admin and others

I’m guessing you’re talking about builder tools. When a player uses builder tools, only they can see the buildings unless the admin panel replicates it to the server. If it’s not replicated to the server, then you can’t save it. In order to save it, you would have to send the buildings to the server through a remote event, but the buildings won’t be passed because it doesn’t exist for the server.

is there anyway to make the whole game save every 1 minute and rewrite the last save. (every new build and any edits.)

There’s a way to make the game autosave if you put it in a while true do loop, but I’d recommend not autosaving every minute because then roblox won’t save data if too many requests are made. Every 5 minutes is good, but first check if the buildings replicate to the server. You can easily do this by building something first and then checking if you can see it on the server. If you can’t see it on the server, then adding this code will be useless.

while true do
	task.wait(300)
	for i, player in pairs(game.Players:GetChildren()) do
	local success, err = pcall(function()
		datastore:SetAsync("Player_"..tostring(player.UserId), value) -- Saving the player's data
	end)
	if err then warn(err) end
	end
end

Simply convert parts into JSON, save all non-default properties and you are done in saving the world. And in terms of getting, it’s the same but in reverse. Convert JSON into roblox tables, and then change properties of that part accordingly to what does JSON have in the table.

I build my models wait 5 minutes then leave and there not there. (They are in workplace when in)

Tryed put it in ReplicatedServer, ServerStorage and severscriptservice.

How would I script that? I am a beginner scripter.