-
What do you want to achieve? To clone a sword and place it in the player’s backpack per round and removing it once the round is over
-
What is the issue? Once a new round starts this error appears
-
What solutions have you tried so far? I have tried to look for solutions using the devforum but none have worked for me
The error appeears once the round has finished once and causes the rest of the script to stop indefinitely
--Variables
local lobbyPart = game.Workspace.SpawnLocation
local maps = game.ReplicatedStorage.Folder:GetChildren()
local status = game.ReplicatedStorage.Status
local inRound = game.ReplicatedStorage:WaitForChild("InRound")
local playersAlive = {}
local sword = game.ReplicatedStorage.ClassicSword:Clone()
local function choseMap(char, internval) -- chose map
local mapsNo = math.random(1, #maps)
local chosenMap = maps[mapsNo]:Clone()
chosenMap.Parent = workspace
print(chosenMap.Name)
char.HumanoidRootPart.Position = chosenMap.TeleportPoint.Position
if internval == 0 then
task.wait(4)
chosenMap:Destroy()
end
end
local function round() -- start intermission and round
for i, v in pairs(game.Players:GetPlayers()) do
table.insert(playersAlive, i, v)
if inRound == true then
inRound = false
break
end
local char = v.Character or v.CharacterAdded:Wait()
if char.Humanoid then
local hum = char.Humanoid
for i = 30, 0, -1 do
status.Value = "Intermission: "..i
task.wait(1)
end
choseMap(char,i)
status.Value = "Map Chosen!"
task.wait(5)
sword.Parent = v.Backpack
for i = 120, 0, -1 do -- change i to 120 when done testing, 10 during testing
hum.Died:Connect(function()
table.remove(playersAlive, i)
print(playersAlive)
if #playersAlive == 1 then
local winner = playersAlive[i]
status.Value = "Round Ended"
wait(5)
inRound = true
if v.Name == winner.Name then
local leaderstats = playersAlive[i].leaderstats
local coins = leaderstats.Coins
local wins = leaderstats.Wins
wins.Value = wins.Value + 1
coins.Value = coins.Value + 200
coins.Value = coins.Value
else
local leaderstats = v.leaderstats
local coins = leaderstats.Coins
coins.Value = coins.Value + 50
end
end
end)
status.Value = "Time Left: "..i
if i == 0 then
sword:Destroy()
v.Character.HumanoidRootPart.Position = lobbyPart.Position
end
task.wait(1)
end
end
end
end
while true do
round()
task.wait()
end