i had i problem. im a youtuber and im a basic coder! i draw a simple code that works but sometimes its doesn't work! if someone win sometimes thats not destroying the map and teleports to lobby.
local ok
local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
local plrs = game.Players:GetChildren()
if #plrs > 0 then
t = 20
repeat
t = t-1
s.Value = "Intermission.. "..t
wait(1)
until t == 0
s.Value = "Game starting!"
wait(2)
local mapselect = game.ReplicatedStorage.Games:GetChildren()
local choose = math.random(1,#mapselect)
curnum = 0
for i =1,#mapselect do
curnum = curnum +1
if curnum == choose then
mapselect[i]:Clone().Parent = workspace
curmap = mapselect[i].Name
s.Value = "We'll be playing "..mapselect[i].Name
ok = true
end
end
wait(3)
if ok == true then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local num = math.random(1,16)
plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
plrs[i].Character.Parent = workspace.Ingame
end
end
t=100
repeat
t = t-1
s.Value = t.." seconds left"
wait(1)
local ingame = workspace.Ingame:GetChildren()
until t ==0 or vals.Winner.Value ~= "" or #ingame == 0
if vals.Winner.Value ~= "" then
s.Value = vals.Winner.Value.. " has won!"
game.Players[vals.Winner.Value].leaderstats.Points.Value = game.Players[vals.Winner.Value].leaderstats.Points.Value +50
game.Players[vals.Winner.Value].leaderstats.Wins.Value = game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
vals.Winner.Value = ""
ok = false
else
s.Value = "No one has won! LMAO"
ok = false
end
wait(3)
if ok == false then
local ingame = workspace.Ingame:GetChildren()
for i =1,#ingame do
local plr = game.Players:GetPlayerFromCharacter(ingame[i])
plr:LoadCharacter()
if ok == false then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local numspawn = math.random(1,16)
plrs[i].Character.Head.CFrame = CFrame.new(workspace.Spawn["Part"..numspawn].Position)
plrs[i].Character.Parent = workspace.Ingame
ok = true
end
end
end
end
wait(4)
workspace[curmap]:Destroy()
else
s.Value = "2 player are needed to play!"
wait(1)
end
end

1 comment
Please format your code and tell me where is the error.