Datastore2 Saving Gui Button state (Visibility)

I have a Datastore2 setup and working for my leaderstats, but I am now trying to save a Gui button’s visibility… When someone buys an item, the button disappears and I want it to save that state, so that when players log back in, they can’t buy the save product again.

I tried saving the visible bool in the same manner that I saved my stats, but without success (I am fairly new to scripting)

So my question is, how can I achieve this?
Additional info: The shop is showed when a part is touched and the purchase is client to server with a remote

My Code

    local DataStore2 = require(1936396537) --//Stats = Master key

    DataStore2.Combine("Stats", "Crystals", "Coins", "Rubies", "Rebirths", "Multiplier")
    Players = game:GetService("Players")
    game.Players.PlayerAdded:Connect(function(player)--PlayerAddedFunction

    	--//Datastore2 Vars
    	local dataCoinsLife = DataStore2("CoinsLife",player)
    	local dataCrystals = DataStore2("Crystals",player)
    	local dataCoins = DataStore2("Coins",player)
    	local dataRubies = DataStore2("Rubies",player)
    	local dataRebirths = DataStore2("Rebirths",player)
    	local dataMultiplier = DataStore2("Multiplier",player)
    	--//End DataStore2 Vars

    	local leaderstats = Instance.new("Folder") -- Creating the Folder
    	leaderstats.Name = "leaderstats" -- Naming the Folder
    	leaderstats.Parent = player -- Setting the folder's parent

    	--CURRENCIES---------------------------------------------------------------------------------------------

    	--Main Currency------------------------------------------------------------------------------------------
    	local Crystals = Instance.new("IntValue") -- Creating the InValue for currency
    	Crystals.Name = "Crystals" -- Name displayed on leaderboard
    	Crystals.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	Crystals.Value = 0 -- Initial Value

    	--Second Currency------------------------------------------------------------------------------------------
    	local Coins = Instance.new("IntValue") -- Creating the InValue for currency
    	Coins.Name = "Coins" -- Name displayed on leaderboard
    	Coins.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	Coins.Value = 0 -- Initial Value
    	local CoinsLife = Instance.new("IntValue") -- This is a lifetime version of the coins for the inworld leaderboard
    	CoinsLife.Name = "CoinsLife" -- Name displayed on leaderboard
    	CoinsLife.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	CoinsLife.Value = 0 -- Initial Value

    	--Premium Currency------------------------------------------------------------------------------------------
    	local Rubies = Instance.new("IntValue") -- Creating the InValue for currency
    	Rubies.Name = "Rubies" -- Name displayed on leaderboard
    	Rubies.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	Rubies.Value = 0 -- Initial Value

    	--Rebirths-------------------------------------------------------------------------------------------------
    	local Rebirths = Instance.new("IntValue") -- Creating the InValue for currency
    	Rebirths.Name = "Rebirths" -- Name displayed on leaderboard
    	Rebirths.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	Rebirths.Value = 0 -- Initial Value

    	--Multiplier----------------------------------------------------------------------------------------------
    	local Multiplier = Instance.new("IntValue") -- Creating the InValue for currency
    	Multiplier.Name = "Multiplier" -- Name displayed on leaderboard
    	Multiplier.Parent = leaderstats -- The currencie's parent is the leaderstats Folder
    	Multiplier.Value = 1 -- Initial Value

    	--END CURRENCIES-----------------------------------------------------------------------------------------------
    	--//Load Data
    	
    	if dataCoinsLife:Get() ~= nil then
    		CoinsLife.Value = dataCoinsLife:Get()
    	else
    		CoinsLife.Value = 0
    	end
    	
    	if dataCrystals:Get() ~= nil then
    		Crystals.Value = dataCrystals:Get()
    	else
    		Crystals.Value = 0
    	end

    	if dataCoins:Get() ~= nil then
    		Coins.Value = dataCoins:Get();
    	else
    		Coins.Value = 0
    	end

    	if dataRubies:Get() ~= nil then
    		Rubies.Value = dataRubies:Get()
    	else
    		Rubies.Value = 0
    	end

    	if dataRebirths:Get() ~= nil then
    		Rebirths.Value = dataRebirths:Get()
    	else
    		Rebirths.Value = 0
    	end

    	if dataMultiplier:Get() ~= nil then
    		Multiplier.Value = dataMultiplier:Get()
    	else
    		Multiplier.Value = 1
    	end

    	--//Save Data
    	CoinsLife.Changed:Connect(function()
    		dataCoinsLife:Set(CoinsLife.Value)
    	end)

    	Crystals.Changed:Connect(function()
    		dataCrystals:Set(Crystals.Value)
    	end)

    	Coins.Changed:Connect(function()
    		dataCoins:Set(Coins.Value)
    	end)

    	Rubies.Changed:Connect(function()
    		dataRubies:Set(Rubies.Value)
    	end)

    	Rebirths.Changed:Connect(function()
    		dataRebirths:Set(Rebirths.Value)
    	end)

    	Multiplier.Changed:Connect(function()
    		dataMultiplier:Set(Multiplier.Value)
    	end)	
    end)
1 Like

I would save it to a table like this. Maybe save it using player.Removing.

local visibletable = {}

local button1 = -- define
local button2 = -- define
local button3 = --define

visibletable.Item1 = button1.Visible
visibletable.Item2 = button2.Visible
visibletable.Item3 = button3.Visible
print(visibletable)
dataVisibles:Set(visibletable)
1 Like

Okay, I think I understand, I will give this a try thank you for your time here.

Edit: Can I add the table to the combined keys? Or make a new script?