So, I’ve been wanting to save gui to a data store. And, how I want it to work is, when you join the game and press a button, a frame, button, etc is visible or not visible. But when you join the game, if you make it visible, it stays visible when you rejoin. And if you make it invisible, then it stays invisible when rejoining. And I looked around on google to figure out how to do this and none of them are giving me the answer I’m looking for.
just make a boolvalue for visible, save its value when the player leaves and call back the value when they join.
Where would I put the bool value?
put the boolvalue inside of the gui.
Ah alright. I’ll give it a try.
This is for saving:
Fire a remote event when a player makes it invisible or invisible, and when the server receives the Remote Event request, then just simply, save the Visible property of the Frame.
This is for loading it:
When the player joins the game, check if the player has their data stored, if they do, then just do
local Visibility local success, errormessage = pcall(function() Visibility = YOURDATASTORE:GetAsync() -- Put in your key that you assigned the data to. end) if success and Visibility then Player.PlayerGui.YOURGUI.YOURFRAME.Visible = Visibility end
Hope this helped you!
If you read some articles about DataStores on the Developer Hub, you would recognise that you can’t save instances to DataStores because they can’t be serialised. This would allow you to form a better and direct question of “how can I save the visibility state of a Gui?” or similar.
Responses above are sufficient enough for doing this. Just remember that if you’re saving other kinds of data, you should consolidate such that the visibility of said Gui is part of your overall player data table.
Didn’t work. I added some print messages to see what was going on, and the output printed this: Argument 2 missing or nil.
You could just store the value of
Visible in a datastore like so:
-- Get the services we need. local dataStoreService = game:GetService("DataStoreService") local players = game:GetService("Players") -- Get when a player joins players.PlayerAdded:Connect(function(plr) -- Get the player's datastore local ds = dataStoreService:GetDataStore(tostring(plr.UserId)) local success, response = pcall(function() -- Get the value return ds:GetAsync("gui_visible") end) -- Check if the request failed (if not, continue) if (success) then -- Check if the value is set to true if (response) then [FRAME].Visible = true else -- If the value is either false or it was never set [FRAME].Visible = false end end end) players.PlayerRemoving:Connect(function(plr) -- Get the player's datastore local ds = dataStoreService:GetDataStore(tostring(plr.UserId)) -- Attempt to set the value ds:SetAsync("gui_visible", [FRAME].Visible) end)
If you have any questions about this, let me know. I tried to explain what I was doing as well as I could with the comments.
Thank you so much! It actually worked!
Could you tell me what did you do to get it to work, because I tried that solution and it is not saving the data.
and how about saving the UI text?
The text of a GUI contains string values. Thus, the value type you would be saving is a string value. In this case of storing whether the frame is visible or not, you use boolean values. To save strings as you want, do the same method and assign the Text Attribute of the UI in a string format into datastore. There is just a difference between the value types. Once the player is loaded, retrieve what was stored personally for a specific player, and assign the value back into your specified UI.
what is [FRAME] in your code