Why is :Clone() is Cloning a folder in server storage twice?

Hello Developers! I have a script which clones a folder in server storage and puts it into workspace. However when it clones its first object it clones it twice, however when I later clone another folder then it only spawns it once. I would like my script to not clone it twice. I have not done a lot of tests and maybe the second one also gets cloned twice but I dont think it does because I tested it once and it didnt, only the first folder got cloned twice. If anyone can help me it will be highly appreciated.
Here is my code:

local event = game.ReplicatedStorage.Event
local Waves = game.ServerStorage.Waves


local function onEvent()
wait (0.5)
local Wave1 = Waves.Wave1:Clone()
wait (0.5)
Wave1.Parent = game.workspace
repeat 
wait(0.5) 
until game.Workspace.Wave1.Monsters.Value == 0 
game.Workspace.Wave1:Destroy()
local Wave2 = Waves.Wave2:clone()
Wave2.Parent = game.workspace
repeat 
wait(0.5) 
until game.Workspace.Wave2.Monsters.Value == 0 
game.Workspace.Wave2:Destroy()



	

end

event.Event:Connect(onEvent)
1 Like

Can you give us a video of that happening?

1 Like

Why do you need a video? I explained it very well. When I go into server mode I can clearly see 2 “Wave1” folders.

Can you share the script which fires the event?

Ok it is a liitle long do you want the entire script or the part which fires the event?

The part which fires the event

local event = game.ReplicatedStorage.Event

-- Give them a sword and a revolver
				local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
				
				if equipped.Value ~= "" then
					local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
					weapon.Parent = player.Backpack
				else
					local Knife = ServerStorage.Pistol:Clone()
					    Knife.Parent = player:WaitForChild("Backpack")
				end
				
			
		--this is the part which fires the event
		                    event:Fire()
				print ("EventFired")

Also it is a bindable event

How many times does it print EventFired?

I havent checked I will check now.

It prints it 2 times like this:

EventFired(x2)

You need to fix this script, the other one is not causing this issue. You need to make it so it only prints EventFired once at a time.

Like what @takticiadam said,

Can we get a video?

Ok I understand that, but I dont know what do I do to change the script, im confused.

A video is unnecessary. The event is being fired twice, hence causing the duplication.

1 Like

Send the entire script here or use pastebin

1 Like

Ok I will:
Also this script isnt entirly made by me I have just changed it up

-- Define variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 360

local reward = 1

local cash = math.random(1200,3500)

local event = game.ReplicatedStorage.Event


 





-- Game loop

while true do
	
	Status.Value = "Waiting for enough players to start"
	
	repeat wait() until game.Players.NumPlayers >= 2
	
	Status.Value = "Intermission"
	
	wait(20)
	
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) -- Add each player into plrs table
		end
	end
	
	local AvailableMaps = MapsFolder:GetChildren()

	local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
	
	Status.Value = ChosenMap.Name.." is the chosen Map"
	
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = workspace
	
	-- Teleport players to the map
	Status.Value = "Preparing Arena"
	wait (5)
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("Spawnpoints not found!")		
	end
	
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	 
	
	
	for i, player in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then
				
				-- Teleport them
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
				table.remove(AvailableSpawnPoints,1)
				
				
				
				-- Give them a sword and a revolver
				local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
				
				if equipped.Value ~= "" then
					local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
					weapon.Parent = player.Backpack
				else
					local Knife = ServerStorage.Pistol:Clone()
					    Knife.Parent = player:WaitForChild("Backpack")
				end
				
			
				                    event:Fire()
				print ("EventFired")
				

				
				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
				
			else
				-- There is no character
				if not player then
					table.remove(plrs,i)
				end
			end
		end
	end
	

	
	
	
	for i = GameLength,0,-1 do
		
		for x, player in pairs(plrs) do
			if player then
				
				character = player.Character
				
				if not character then
					-- Left the game
					table.remove(plrs,x)
				else
					if character:FindFirstChild("GameTag") then
						-- They are still alive
						print(player.Name.." is still in the game!")
					else
						-- They are dead
						table.remove(plrs,x)
						print(player.Name.." has been removed!")
					end
				end
			else
				table.remove(plrs,x)
				print(player.Name.." has been removed!")
			end
		end
		
		Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
		
		
		if #plrs == 0 then
			Status.Value = "Monsters have defeated you!"
			break
		elseif i == 0 then
			Status.Value = "You have defeated the Monsters!"
			plrs.leaderstats.Wins.Value = plrs.leaderstats.Wins.Value + reward
			plrs.leaderstats.Coins.Value = plrs.leaderstats.Coins.Value + cash
			break
		end
		
		
		wait(1)
	end
	
	print("End of game")
	
	wait(2)
	
	for i, player in pairs(game.Players:GetPlayers()) do
		character = player.Character
		
		if not character then
			-- Ignore them
		else
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
			end
			
			for _, tool in pairs(player.Backpack:GetChildren()) do
				if tool:FindFirstChild("Price") then
					tool:Destroy()
				end
			end
			
			for _, tool in pairs(character:GetChildren()) do
				if tool:FindFirstChild("Price") then
					tool:Destroy()
				end
			end
			
		end
		
		player:LoadCharacter()
	end
	
	ClonedMap:Destroy()
	
	Status.Value = "Game ended"
	
	wait(2)
end

Move the firing of the event outside of the for loop.

Ok I will try that. What line do you recommend me to put it?

After you loop through the players.

end
	--In between those two?	
		Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"