-
What do you want to achieve? Keep it simple and clear!
I am trying to wrap my round system in a pcall so that it doesn’t stop working if something happens for example: a target user leaving the game unexpectedly. -
What is the issue? Include screenshots / videos if possible!
I get this error:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have searched the developer hub and forums but found no similar problems to mine.
Here is my script located in ServerScriptService:
local maps = game.ReplicatedStorage:WaitForChild("Maps")
local status = game.ReplicatedStorage:WaitForChild("Status")
while true do
local pcal = pcall(function(err)
local maps = game.ReplicatedStorage:WaitForChild("Maps")
local status = game.ReplicatedStorage:WaitForChild("Status")
local players = game.Players
status.Value = "Waiting for players..."
repeat wait() until #players >= 2
for i = 30,0,-1 do
status.Value = "Round starts in "..i.." seconds!"
wait(1)
end
status.Value = "Choosing map..."
wait(5)
local chosenmap = maps:GetChildren()[math.random(1,#maps:GetChildren())]:Clone()
chosenmap.Parent = workspace
status.Value = chosenmap.Name.." was chosen!"
wait(7)
status.Value = "Round starting..."
wait(3)
local NumberOnUnrounded = #players:GetPlayers() / 3
local NumberOn = math.round(NumberOnUnrounded)
local NumberOff = #players:GetPlayers() - NumberOn
local numOn = 0
local hiderSpawn = chosenmap:WaitForChild("HiderSpawn")
local itSpawn = chosenmap:WaitForChild("ItSpawn")
for i, v in pairs(players:GetPlayers()) do
if not v:FindFirstChild("Tag") then
local tag = Instance.new("BoolValue")
tag.Name = "Tag"
tag.Parent = v
if numOn < NumberOn then
tag.Value = true
numOn = numOn + 1
end
end
end
for i, v in pairs(players:GetPlayers()) do
if v:FindFirstChild("Tag") then
local char = v.Character
local root = char:WaitForChild("HumanoidRootPart")
if v.Tag.Value == true then
root.CFrame = itSpawn.CFrame
wait(0.05)
root.Anchored = true
elseif v.Tag.Value == false then
root.CFrame = hiderSpawn.CFrame
end
end
end
wait(3)
for i = 30,0,-1 do
status.Value = "The Seekers will be released in "..i.." seconds!"
wait(1)
end
for i, v in pairs(players:GetPlayers()) do
if v:FindFirstChild("Tag") then
if v.Tag.Value == true then
local char = v.Character
local root = char:WaitForChild("HumanoidRootPart")
root.Anchored = false
end
end
end
local num = 0
for i = 60, 0, -1 do
status.Value = "Time Remaining: 2 minutes and "..i.." seconds."
for index, val in pairs(players:GetPlayers()) do
if val:FindFirstChild("Tag") then
if val.Tag.Value == false then
num = num + 1
end
end
end
if num >= 1 then
elseif num < 1 then
break
end
wait(1)
end
num = 0
for i = 60, 0, -1 do
status.Value = "Time Remaining: 1 minute and "..i.." seconds."
for index, val in pairs(players:GetPlayers()) do
if val:FindFirstChild("Tag") then
if val.Tag.Value == false then
num = num + 1
end
end
end
if num >= 1 then
elseif num < 1 then
break
end
wait(1)
end
num = 0
for i = 60, 0, -1 do
status.Value = "Time Remaining: "..i.." seconds."
for index, val in pairs(players:GetPlayers()) do
if val:FindFirstChild("Tag") then
if val.Tag.Value == false then
num = num + 1
end
end
end
if num >= 1 then
elseif num < 1 then
break
end
wait(1)
end
for i, v in pairs(players:GetPlayers()) do
if v.Tag then
v:LoadCharacter()
end
end
if num == 0 then
status.Value = "The Seekers have won!"
elseif num >= 1 then
status.Value = "The Hiders have won!"
end
wait(6)
warn("Error: "..err)
end
end) --the error is here