How to prevent a clone script from cloning multiple ui?

Hello, does anyone know how to prevent a clone script from cloning the UI more than once. Here is the script, any help is appreciated.

game.ReplicatedStorage:WaitForChild("remoteTutorials").ChangedTut.OnServerEvent:Connect(function(Player)

local popStarters = Player:WaitForChild("worldStats").StartingValue
local popPoints = Player:WaitForChild("leaderstats").Pops
local requiredXP = Player:WaitForChild("worldStats").PopsRequired
local Character = Player.Character
local db1 = false

	
	popPoints:GetPropertyChangedSignal("Value"):Connect(function()
		task.wait(0.1)
		if db1 == false then
			local playerGui = Player:WaitForChild("PlayerGui")

			if popPoints.Value >= requiredXP.Value then	
				if Player.tutorialStats.didTutorial.Value == "true" then 
				db1 = true	
				local purchaseFrame = script:WaitForChild("UnlockNextMap"):Clone()
					purchaseFrame.Parent = playerGui
					db1 = false
	
					end	
				end
			end	
		end
	end)
end)

You can check if it already exists with FindFirstChild()

if not script:FindFirstChild("UnlockNextMap") then
      -- clone it
end
-- if it is there it skips over and keeps going

Edit: Please mark as solution so others don’t try to solve something already solved @RangelBrothers

1 Like

It does not work when I tried to test it.

Any errors? Could you show your code?

game.ReplicatedStorage:WaitForChild("remoteTutorials").ChangedTut.OnServerEvent:Connect(function(Player)

	local popStarters = Player:WaitForChild("worldStats").StartingValue
	local popPoints = Player:WaitForChild("leaderstats").Pops
	local requiredXP = Player:WaitForChild("worldStats").PopsRequired
	local Character = Player.Character
	local db1 = false


	popPoints:GetPropertyChangedSignal("Value"):Connect(function()
		task.wait(0.1)
		if db1 == false then
			local playerGui = Player:WaitForChild("PlayerGui")

			if popPoints.Value >= requiredXP.Value then	
				if Player.tutorialStats.didTutorial.Value == "true" then 
					if not script:FindFirstChild("UnlockNextMap") then
					db1 = true	
					local purchaseFrame = script:WaitForChild("UnlockNextMap"):Clone()
					purchaseFrame.Parent = playerGui
						db1 = false
						
					end
				end
			end	
		end
	end)
end)

You are setting the parent to playerGui but checking if it is in the script

try

if not playerGui:FindFirstChild("UnlockNextMap") then

end

It works the first time when I exit the UI and retry, it does not clone again.