Ok I know, I mean to make it disabled so when a joins and clicks it and then joins again it will still be invisible
You mean across game sessions? As in when it shuts down the server? If it’s within the same game session @Afraid4Life’s solution would still work.
Yes
you need to use datastores to see if they’ve clicked the button before: here’s a good tutorial
you could just do Destroy() instead of button.visible = false.
If I may ask, what is this used for? Wouldn’t it be easier to just set the visibility manually?
It is used for an rp game I made a character selection gui but I want them to only to have access to it once
If you never want this button visible again, simply destroy it:
<BUTTONNAME/LOCATION>:Destroy()
Keep in mind with the datastore, unless you have a mechanism to make it visible again, it would remain invisible forever (maybe not forever forever but you get the idea heh).
He wants it to remain invisible across game sessions.
The only ways to make something invisible is to make Visible
false or to destroy
it. You can also disable the ScreenGui by clicking the ScreenGui and making sure Enabled
is false.
So it will only destroy for the player right?
If you destroy it from the PlayerGui (local player folder called PlayerGui), yes.
Ok my other question is what if I left the server and joined another will it still be destroyed
No. From what I know, you rejoined which means everything will locally reset, meaning that the “button” will be visible for you again.
Ok so how do I make it not visible for me again?
If you destroy it, its gone. You can always store a backup in ReplicatedStorage and if you want it visible again, you can :Clone it from replicated storage and parent it to the PlayerGui. Another way is to just make Visible
false.
You need to set up a data store and have it set a value in the datastore if it was destroyed and check the key in future sessions if it was destroyed and re-destroy it if it was.
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!
Ok thank you I will try it