How to make frame invisible on rejoin

How would i make it so that the frames that i turned false and true in the script stay like that upon rejoining ```MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local DevProductID = 2690116131 – Replace with your actual Developer Product ID

local giveTokensEvent = ReplicatedStorage:WaitForChild(“GiveTokensEvent”)

– Reference the button and its parent frame
local button = script.Parent
local buttonFrame = button.Parent – The parent of the button (the frame that contains the button)
local scrollingFrame = buttonFrame.Parent – The parent of the buttonFrame (the scrolling frame)
local offerFrameClone = scrollingFrame:WaitForChild(“Offer1FrameClone”) – The frame to be shown after purchase
local TokenAmount = 2000000
– Hide the offer frame clone initially (in case it is visible by default)
offerFrameClone.Visible = false

– Function to handle the button click
button.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer – Get the local player
if player then
– Trigger the purchase when the button is clicked
MarketplaceService:PromptProductPurchase(player, DevProductID)
else
warn(“LocalPlayer not found!”)
end
end)

– Listen for purchase completion
MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productId, wasPurchased)
if wasPurchased and productId == DevProductID then
– Hide the current frame (the parent of the button)
giveTokensEvent:FireServer(TokenAmount)
buttonFrame.Visible = false

	-- Make the new frame (Offer1FrameClone) visible and ensure it stays visible
	offerFrameClone.Visible = true
	-- Disable this frame from ever becoming visible again
end

end)```

1 Like

The only way I can think of to do this would be to use a datastore and have some values that dictate whether or not they have the frame open.

if your game already has a data store then i would just use that one because making a whole datastore just for a couple bool values is kind of unnecessary.

1 Like

I agreed with this, for example : To keep frames the same after rejoining, you can use DataStore to save their visibility state when they change (e.g., after a button is clicked), then load that saved state when the player rejoins.