How can i make a gui's properties save

Hello,
im making a game and for my game i want to save the propperties of some gui, gui as button and txt labels. The name of the ui, the visibility, so .visible = true/false, and the text are the properties i’d like to save.

But how can i achieve this using data stores, and is this even possible?

Run through all the properties and create a bool value/string value/int value/etc and save it to a datastore.

Edit: Actually the response below is a better method, if its only going to be accessed for saving.

1 Like

This would be the same as how you normally save your stats.

Make a Table like I did below. It has the name of the Button as the table name and then add the parameters you want to save inside. I don’t believe you can save ObjectValues, so if you have the same name for some, just give them a unique Id.
Make sure to set Attributes like Id to the Gui Object to know which UI the table is holding the properties for and to set it.

The table would look like this :

["Button"] = 
{
    Visible = true
    Position = Udmi2.new(0,0,0,0);
    Size = Udmi2.new(0,0,0,0);
    GUIType = "TextButton"
    Id = 1
};

["Button"] =  -- A  duplicate
{
    Visible = false
    Position = Udmi2.new(0,0,0,0);
    Size = Udmi2.new(0,0,0,0);
    Id = 2
};

["Frame"] = 
{
    Name = "MyFrame";
    BackgroundColor3 = color3.rgb(255,255,255)
}
2 Likes

Uhhh, i will look into this later but thanks

Okay so why does this not work?

-- // services
local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local dataStore = dataStoreService:GetDataStore("Gui")


-- // variables

local keyPrefix = "Player: "
local Guis = game.StarterGui.Upgrades.Main.MainUpgrades:GetChildren()


-- // functionsq


local function save(player: Player)
	local key = keyPrefix .. tostring(player.UserId)
	local data = {}
	
	for i, gui: GuiBase in ipairs(Guis) do
		table.insert(data, {
			gui.Name,
			gui.Visible,
			gui.Text
		})
	end
	
	local succes, err
	
	repeat
		succes, err = pcall(function()
			dataStore:UpdateAsync(key, function()
				return data
			end)
		end)
		
		task.wait()
		
	until succes
	
	if not succes then
		warn("Djalla geen succes met saven g: " .. tostring(err))
	end
	
	
end

local function load(player: Player)
	local key = keyPrefix .. tostring(player.UserId)
	
	local succes, err
	local data
	repeat
		succes, err = pcall(function()
		data = dataStore:GetAsync(key)
		end)
		
	until succes or not player:FindFirstChild(player.Name)
	
	if not data then return end
	
	if succes then
		
		for i, gui in ipairs(data) do
			gui.Name = data[1]
			gui.Visible = data[2]
			gui.Text = data[3]
		end
		
		
		else
		warn("Ja g weer gefaald womp womp: " .. tostring(err))
	end

end


-- // signals

players.PlayerAdded:Connect(save)
players.PlayerRemoving:Connect(load)

game:BindToClose(function()
	for i, plr: Player in ipairs(players:GetPlayers()) do
		save(plr)
	end
end)

If you want to save a certain player’s gui properties then you’ll have to access it from the player’s client side to get those properties. then you’ll have to save it.

In this code you are just getting the gui directly from the starterGui Which bascially won’t change any parameters. It’s just gonna duplicate and give the Gui to the player, thats all.

I’ll write a sample code later on.

huh, but how the hell would i do that

There are multiple ways you can do this!

  1. you can make a save button for the players and if they click it the properties will be saved. (Use this if saving is not neccessary).
  2. Fire a remoteEvent from the client side with the properties you wish to save whenever a property you wish to save changes.
  3. Keep everything on the serverside as a value and when ever you want to change the player gui change the value and not the gui it self. And make sure to make a script in the clien side where if the value is changed the corresponding value will be given to the gui (safer method if you don’t want hackers to play around with their own data storage)

Keep in mind to not trust the client side as hackers can always fire the remoteevent whenever they want and change the properties to their liking.

1 Like

Its fixed, someone else helped me, but thanks for ur time!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.