How would i make a gui enabled forever after i click a button

Alright so im making a game in which you can buy a tool. theres a button that gives u the tool and enables a different script. How would i make that script be enabled even after the player rejoins? Could anyone give me a script that would do that?

3 Likes

you need to use datastore to check after rejoining

2 Likes

How would i exactly do that???

bool value named uival will be saved as true if player got true (first time joined player will get false)
you can enable ui if player have true for uival.Value

local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("PlayerDatastore")



game.Players.PlayerAdded:Connect(function(player)
	local uival = Instance.new("BoolValue")
	uival.Parent = player
	uival.Name = "uival"	
	
	local tableOfData
	local success, errormessage = pcall(function()
		tableOfData = datastore:GetAsync(player.UserId)
	end)
	if tableOfData then
		for key, value in pairs(tableOfData) do
			uival.Value = tableOfData["UI"]
		end
	else
		uival.Value = false --for player joined first time
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local tableOfData = {
			["UI"] = player.uival.Value,
		}
		
	local success, errormessage = pcall(function()
		datastore:SetAsync(player.UserId, tableOfData)
	end)
end)
1 Like

Where can i add the scripts location??

serverscriptservice as serverscript

1 Like

no no. i mean like, the location of the script i want to disable.

what you mean by location of script to disable

you can do this:

local gui = *gui*
local button = *button*

local debounce = false

button.MouseButton1Click:Connect(function()
if not disabled then
disabled = true
gui.Enabled = true
end
end)

Sorry i meant enable. but still

I mean when i click a gui (button) i want the script to be enabled forever.

just write local script inside ui and

game.Players.LocalPlayer.uival:GetPropertyChangedSignal("Value"):Connect(function(val)
    if val then
      script.Parent.enabled = true
   end
end)

local Script = *script*

local guiButton = *button*

guiButton.MouseButton1Click:Connect()
Script.Disabled = false
end)

or you can do this:

local debounce = false

local function Source()

rest of script

end

button.MouseButton1Click:Connect(function()
if not debounce then
debounce = true
Source()
end
end)

Yes that works too. There are many ways to make it enable

i mean you can change script.Parent into something you want to enable if value is true

Since you can’t access data stores in a local script, you need to have a server script to get and then check data, and if it says you’ve played before, you need to use a RemoteEvent to pass that information to the client, for the script to then be able to make the GUI visible.

1 Like

you can just give bool value to player and check if bool value changes into true by checking datastore in serverscript

just like this what i wrote before (as server script
in serverscriptservice)

That wouldn’t be ideal, as anything parented to the player can be changed because of network ownership. In this case, the BoolValue can be manipulated.