Remove gui after purchase [ Leaderstats ]

Hello i need help for a script , i want remove the gui forever after purchase with the leaderstats .
The purpose of the script is that if the player has[ > x value] in the leaderstats then it delet the gui forever
but that doesn’t work someone can help me?

Script here :

Keys = player.leaderstats.Keys
Maps = player.leaderstats.Maps
KeyPrice = 1


function buy()
	
	if Keys.Value >= KeyPrice then
		Keys.Value = Keys.Value - KeyPrice
		script.Parent.Parent.Parent.Frame.Visible = false
		Maps.Value = Maps.Value + 1
		
		if Maps.Value < 0  then
			script.Parent:Destroy()
		end

	end
end



script.Parent.MouseButton1Down:connect(buy)

If there isn’t something important that needs to change when the ScreenGui resets, you can disable ResetOnSpawn, this will make the ScreenGui not change on reset.

If there is something important, you can check again if it should be deleted

local Keys = player.leaderstats.Keys
local Maps = player.leaderstats.Maps
local KeyPrice = 1


local function Remove()
	if Keys.Value >= KeyPrice and Maps.Value < 0  then
		script.Parent:Destroy()
	end
end
local function buy()
	if Keys.Value >= KeyPrice then
		Keys.Value -= KeyPrice
		script.Parent.Parent.Parent.Frame.Visible = false
		Maps.Value += 1
		Remove()
	end
end
Remove()

script.Parent.MouseButton1Down:Connect(buy)
1 Like

it doesn’t work, the gui appears every time I re join the game :confused:

You can either use DataStore , or check when the player joins, if he has enough keys ,and if so, detect the UI and destroy it.

1 Like