Hello, I am creating a round system, and it works. Problem is, when the player dies, it should name a stringvalues value to a number (that is a string.). This error pops up:
Code:
ClassName:
Weird thing is, when this is executed on the top lines of code, it does work.
playing is a table, automatically puts all the players in the table, and removes certain players on certain occasions. Checks every .04 seconds if the table amount less than 1 or equal to 1. (<=).
local RS = game.ReplicatedStorage
local RINP = RS:WaitForChild("RoundInProgress", 5)
local Winner = RINP:WaitForChild("Winner", 5)
local PlayersLeft = RINP:WaitForChild("PlayersLeft", 5)
local Intermission = RS:WaitForChild("Intermission", 5)
local Time = Intermission:WaitForChild("Time", 5)
local Text = RS:WaitForChild("Text", 5)
RINP.Changed:Connect(function()
if RINP.Value == false and Winner.Value == "" then
Text.Value = "ROUND OVER!"
elseif RINP.Value == true then
Text.Value = "Round in progress [ALIVE: " .. PlayersLeft.Value .. "]"
end
end)
while task.wait() do
local playing = {}
Intermission:WaitForChild("Time", 5).Value = 40
Intermission.Value = true
if Intermission.Value == true and Time ~= "0" then
for i = Time.Value, 1, -1 do
Text.Value = "INTERMISSION: [" .. tostring(string.format("%d:%.02d", i/60, i%60, i*1000%1000)) .. "]"
task.wait(1)
end
end
Intermission.Value = false
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(playing, v)
end
Text.Value = "SETTING UP ROUND"
task.wait(2)
local spawns = game.ServerStorage:WaitForChild("MapSpawns"):Clone()
spawns.Parent = game.Workspace
local points = {}
for i,v in pairs(spawns:GetDescendants()) do
table.insert(points, v)
end
for i,v in pairs(points) do
local val = Instance.new("BoolValue")
val.Name = "Taken"
val.Value = false
val.Parent = v
end
for i,v in pairs(playing) do
local char = v.Character
if char then
pcall(function()
local function entries()
local chosen = points[math.random(#points)]
if chosen.Taken.Value == false then
chosen.Taken.Value = true
char.HumanoidRootPart.Position = chosen.Position
char.HumanoidRootPart.Anchored = true
else
return false
end
end
local MAX_ENTRIES = 0
local s, r = pcall(function()
entries()
end)
if r == false then
repeat
local s, r = pcall(function()
entries()
end)
MAX_ENTRIES += 1
until r ~= false or MAX_ENTRIES >= 6
end
end)
end
PlayersLeft.Value = tostring(#playing)
for i = 3, 1, -1 do
Text.Value = "STARTING IN: " .. tostring(i)
task.wait(1)
end
for i,v in pairs(playing) do
pcall(function()
v.Character.HumanoidRootPart.Anchored = false
local event
event = v.Character.Humanoid.Died:Connect(function()
table.remove(playing, i)
PlayersLeft.Value = tostring(#playing)
event:Disconnect()
end)
game.ServerStorage:WaitForChild("Sword", 5):Clone().Parent = v.Backpack
end)
end
RINP.Value = true
local RS = game.ReplicatedStorage
local RINP = RS:WaitForChild("RoundInProgress", 5)
local Winner = RINP:WaitForChild("Winner", 5)
local PlayersLeft = RINP:WaitForChild("PlayersLeft", 5)
local Intermission = RS:WaitForChild("Intermission", 5)
local Time = Intermission:WaitForChild("Time", 5)
local Text = RS:WaitForChild("Text", 5)
RINP.Changed:Connect(function()
if RINP.Value == false and Winner.Value == "" then
Text.Value = "ROUND OVER!"
elseif RINP.Value == true then
Text.Value = "Round in progress [ALIVE: " .. tostring(PlayersLeft.Value) .. "]"
end
end)
while task.wait() do
local playing = {}
Intermission:WaitForChild("Time", 5).Value = 10
Intermission.Value = true
if Intermission.Value == true and Time ~= "0" then
for i = Time.Value, 1, -1 do
Text.Value = "INTERMISSION: [" .. tostring(string.format("%d:%.02d", i/60, i%60, i*1000%1000)) .. "]"
task.wait(1)
end
end
Intermission.Value = false
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(playing, v)
end
Text.Value = "SETTING UP ROUND"
task.wait(2)
local spawns = game.ServerStorage:WaitForChild("MapSpawns"):Clone()
spawns.Parent = game.Workspace
local points = {}
for i,v in pairs(spawns:GetDescendants()) do
table.insert(points, v)
end
for i,v in pairs(points) do
local val = Instance.new("BoolValue")
val.Name = "Taken"
val.Value = false
val.Parent = v
end
for i,v in pairs(playing) do
local char = v.Character
if char then
pcall(function()
local function entries()
local chosen = points[math.random(#points)]
if chosen.Taken.Value == false then
chosen.Taken.Value = true
char.HumanoidRootPart.Position = chosen.Position
char.HumanoidRootPart.Anchored = true
else
return false
end
end
local MAX_ENTRIES = 0
local s, r = pcall(function()
entries()
end)
if r == false then
repeat
local s, r = pcall(function()
entries()
end)
MAX_ENTRIES += 1
until r ~= false or MAX_ENTRIES >= 6
end
end)
end
PlayersLeft.Value = #playing
for i = 3, 1, -1 do
Text.Value = "STARTING IN: " .. tostring(i)
task.wait(1)
end
for i,v in pairs(playing) do
pcall(function()
v.Character.HumanoidRootPart.Anchored = false
local event
event = v.Character.Humanoid.Died:Connect(function()
table.remove(playing, i)
PlayersLeft.Value = #playing
event:Disconnect()
end)
game.ServerStorage:WaitForChild("Sword", 5):Clone().Parent = v.Backpack
end)
end
RINP.Value = true
game.Players.PlayerRemoving:Connect(function(plr)
for i,v in pairs(playing) do
if plr == v then
table.remove(playing, i)
PlayersLeft.Value = tostring(#playing)
end
end
end)
while task.wait() do
if #playing <= 1 then
pcall(function()
for i,v in pairs(playing) do
RINP.Winner.Value = v.Name
table.remove(playing, i)
end
end)
task.wait(4)
RINP.Value = false
RINP.Winner.Value = ""
PlayersLeft = "0"
end
task.wait(1)
end
end
repeat task.wait(.04) until RINP.Value == false
end