How to save Gui's and models?

Hi Devs, i try to ask to how to save Gui’s like color,s text,s etc:

Frame 1 is white ■ as color and when i pressed a button as example it change to □ black and when i rejoin the color is and will be black nit white because i have set it. The same we i buy an nodel with a button so this model will be save for ever, the buy function is with a leaderstat called at “Points” and when Points:match(Button.label.Text) then etc and when not then nothing happens,

Well i am apologize that i am not the best Scripter, but i try it :pleading_face: can someone help me out???

To do this you could use Values such as intValue,color3Value etc.First create the values on the Server then use a RemoteEvent between the Client and Server to change the values whenever you change colour.Lastly create a Datastore to store the colours in a dictionary format as the data being saved using SetAsync then if the data exists you can uss a remote event between server and client to update the gui.

1 Like

To save GUI properties (like color) and models (like purchased items) in Roblox use DataStoreService.

When a player changes the GUI (e.g. clicks a button to set a Frame to black),save the new color to a DataStore.For models, when a player buys one with points, save its name to a DataStore and spawn it in the workspace.On rejoin, load the saved GUI color and spawn any purchased models from the DataStore

Example:

local DataStoreService = game:GetService("DataStoreService")
local guiData = DataStoreService:GetDataStore("GuiSettings")
local modelData = DataStoreService:GetDataStore("ModelPurchases")

local frame = script.Parent.Frame -- Your Frame
local guiButton = script.Parent.Button -- GUI Button
local buyButton = workspace.BuyButton -- Buy Button
local model = game.ServerStorage.Model -- Model in ServerStorage
local points = game.Players.LocalPlayer.leaderstats.Points -- Points leaderstats

-- Load GUI color
game.Players.PlayerAdded:Connect(function(player)
    local color = guiData:GetAsync("P_" .. player.UserId .. "_Color")
    if color then
        frame.BackgroundColor3 = Color3.fromRGB(color.r, color.g, color.b)
    end
end)

-- Save GUI color
guiButton.MouseButton1Click:Connect(function()
    frame.BackgroundColor3 = Color3.new(0, 0, 0) -- Black
    guiData:SetAsync("P_" .. game.Players.LocalPlayer.UserId .. "_Color", {r=0, g=0, b=0})
end)

-- Load models
game.Players.PlayerAdded:Connect(function(player)
    local models = modelData:GetAsync("P_" .. player.UserId .. "_Models")
    if models then
        for _, modelName in pairs(models) do
            game.ServerStorage[modelName]:Clone().Parent = workspace
        end
    end
end)

-- Save model
buyButton.MouseButton1Click:Connect(function()
    local cost = tonumber(buyButton.Label.Text)
    if points.Value >= cost then
        points.Value -= cost
        model:Clone().Parent = workspace
        local models = modelData:GetAsync("P_" .. game.Players.LocalPlayer.UserId .. "_Models") or {}
        table.insert(models, model.Name)
        modelData:SetAsync("P_" .. game.Players.LocalPlayer.UserId .. "_Models", models)
    end
end)

Everything you did is what his layout should like but you cant use datastores on the client they can only be accessed on the server. Thats why you need to use remote events to communicate between the server and the client to pass the data in the datastore to the client through the server.Thats why i recommend value objects or attributes on the server located inside a dictionary were the player is the key and the value is the data