I’m making a Tower Defense game. I need to save the GUI to the map you teleport to so you can place the towers you equipped.
Saving a GUI is like serializing… there’s a tutorial that introduces this in Roblox.
I believe you’d use MessagingService.
What I’m trying to say is, if you ever played Tower Defense Simulator, you would have noticed the GUI for the towers you equipped saves into the main game.
I’ve always just used datastore service to accomplish this. As long as both places are under the same game, the data saved should be shared between them
They are under the same place. But how do I make a Datastore for a Gui?
You can’t save Instances in DataStores, HOWEVER
You can implement checks (BoolValues) to detect what Towers the Player has, then clone, enable, & parent the GUI’s to the Player that way
Possibly something like this:
--By now we should already have BoolValues both implemented from the lobby to the game place
local DataStore = game:GetService("DataStoreService")
local DataName = DataStore:GetDataStore("TowerCheck")
game.Players.PlayerAdded:Connect(function(Player)
local PlayerGui = Player:WaitForChild("PlayerGui")
local Towers = Instance.new("Folder")
Towers.Name = "Towers"
Towers.Parent = Player
local ScoutCheck = Instance.new("BoolValue")
ScoutCheck.Name "ScoutCheck"
ScoutCheck.Parent = Towers
local Data
local success, whoops = pcall(function()
Data = DataName:GetAsync(Player.UserId)
end)
if success and Data then
ScoutCheck.Value = Data.Scout
end
if ScoutCheck.Value == true then
local ScoutGui = game.ReplicatedStorage.ScoutGui:Clone()
ScoutGui.Parent = PlayerGui.MainGui.TowersFrame
end
end)
local DataStore = game:GetService("DataStoreService")
local DataName = DataStore:GetDataStore("TowerCheck")
game.Players.PlayerAdded:Connect(function(Player)
local PlayerGui = Player:WaitForChild("PlayerGui")
local Towers = Instance.new("Folder")
Towers.Name = "Towers"
Towers.Parent = Player
local ScoutCheck = Instance.new("BoolValue")
ScoutCheck.Name "ScoutCheck"
ScoutCheck.Parent = Towers
local Data
local success, whoops = pcall(function()
Data = DataName:GetAsync(Player.UserId)
end)
if success and Data then
ScoutCheck.Value = Data.Scout
end
if ScoutCheck.Value == true then
local ScoutGui = game.ReplicatedStorage.ScoutGui:Clone()
ScoutGui.Parent = PlayerGui.MainGui.TowersFrame
end
end)
Where should I put the script? Also what game in?
I personally use datastore2 since its a module that makes writing datastore easier for me. I would check it out, but it’s not for everyone.
But I agree with jackscarlett, you can’t save the actual gui objects, you would have to save information about the gui such as “setting 1 enabled” using int or bool values
I only gave a brief example, I can’t spoonfeed entire scripts for you
Your main game handler scripts should go in ServerScriptService
, I’d also recommend debugging it with print()
statements to know if the data loads or not
- Also make sure to enable API Services
Scripts in ServerScriptService
can be used to main server stuff such as DataStores, Gamepass/Badge Checks, Detection Changes & so on