Need help with script

I know this is kind of a stupid topic but I really can’t manage to fix such a small thing:

while wait(0.1) do
    if script.Parent.Visible == true then
    local copy = script.Parent.barapp:Clone()
    copy.Parent = script.Parent.Parent.Parent.appbar
    end
end

I literally can’t manage to make it so the copy will be parented to ‘appbar’ only once

Check if there is already a copy.

How could I do that? I tried using if not [condition] then and broke the entire script

https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild

local parent = script.Parent
local appbar = parent.Parent.Parent:WaitForChild("appbar")

parent:GetPropertyChangedSignal("Visible"):Connect(function()
	if parent.Visible then
		local barapp = script.Parent:FindFirstChild("barapp")
		if barapp then
			local copy = barapp:Clone()
			copy.Parent = appbar
		end
	end
end)
1 Like