Changes to clone affecting every previously cloned part

Hi, could anyone help me with this issue where every time a loop runs, a copy of a script is duplicated to every previously cloned part?

I have a script that clones a GUI frame and then copies a cloned version of a script to make it move down. However, every time the script runs, every previous clone will also get a copy of the script instead of just the most recently cloned one.

Script:

local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ReplicateGUI
local gui2 = player.PlayerGui.ScreenGui
local frame = gui.ZNote
local framescript = gui.ZNoteScript
db = false

while true do
	math.randomseed(os.time())
	wait(math.random(1, 5))
	
	if db == false then
		frameclone = frame:Clone()
		db = true
	end
	wait(1)
	db = false

	frameclone.Visible = true
	print(tostring(frameclone.Visible)) --Debug purposes
	
	frameclone.ZIndex = 3
	framescriptclone = framescript:Clone()
	framescriptclone.Parent = frame
	framescriptclone.Enabled = true
	
	frameclone.Parent = gui2
	
	print(frameclone.Parent) --Debug purposes
end

In the workspace:

Thanks for reading this post lol

local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ReplicateGUI
local gui2 = player.PlayerGui.ScreenGui
local frame = gui.ZNote
local framescript = gui.ZNoteScript
db = false

while true do
	math.randomseed(os.time())
	wait(math.random(1, 5))
	
	if db == false then
		frameclone = frame:Clone()
		db = true
	end
	wait(1)
	db = false

	frameclone.Visible = true
	print(tostring(frameclone.Visible)) --Debug purposes
	
	frameclone.ZIndex = 3
	framescriptclone = framescript:Clone()
	framescriptclone.Parent = frameclone -- This line has been corrected
	framescriptclone.Enabled = true
	
	frameclone.Parent = gui2
	
	print(frameclone.Parent) --Debug purposes
end

Unfortunately its still broken :frowning:

Try this:

local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ReplicateGUI
local gui2 = player.PlayerGui.ScreenGui
local frame = gui.ZNote
local framescript = gui.ZNoteScript
db = false

while true do
    math.randomseed(os.time())
    wait(math.random(1, 5))
    
    if not db then
        local frameclone = frame:Clone()
        frameclone.Visible = true
        frameclone.ZIndex = 3
        frameclone.Parent = gui2
        
        local framescriptclone = framescript:Clone()
        framescriptclone.Parent = frameclone
        framescriptclone.Enabled = true
        
        db = true
    else
        db = false
    end
    
    wait(1)
end

Tysm! Do u know if it was a debounce issue or if it was related to the cloning itself?

In the revised script, the frameclone and framescriptclone are created within the if not db then block, ensuring they are only created once per cycle. The db variable is used as a flag to prevent multiple clones during the same cycle. So it was related to the cloning. :slightly_smiling_face:

1 Like

Ty :smiley: (character minimum limittttttttt)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.