I want to make a button that when pressed will not be visible ever again

here’s how you do it:

Step 1: Make a Local Script inside of the button
Step 2: Create a RemoteEvent in ReplicatedStorage
Step 3: Make sure the Local Script’s input is:

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
end)

Step 4: Create a Server Script in ServerScriptService
Step 5: Make sure the server script’s input is:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	local Button = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Button
	game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
		Button.Visible = false
	end)
	local Data
	local PlayerID = "Player_"..player.UserId
	local success, ErrorMessage = pcall(function()
		Data = DataStore:GetAsync(PlayerID)
	end)
	if success then
		if Data then
			Button.Visible = Data.Button
		end
	else
		warn(ErrorMessage)
	end
end)

function DataSave(player)
	local Data = {
		Button = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Button.Visible,
	}
	local PlayerID = "Player_"..player.UserId
	local Success,ErrorMessage = pcall(function()
		DataStore:SetAsync(PlayerID,Data)
	end)
	
	if Success then
		print("Saved")
	else
		warn(ErrorMessage)
	end
end

Players.PlayerRemoving:Connect(DataSave)

game:BindToClose(function()
	for _, player in pairs(Players:GetPlayers()) do
		DataSave(player)
	end
end)

Step 6: Enable HTTP Requests (Just in case), and Studio Access to API Services in game-settings → Security
Step 7: Test it out!

1 Like

Ok thank you I will try it :grinning: :grinning:

1 Like