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)
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")
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