So this script have problem, when the get ready countdown go to 0, the map disappear and choose a random winner, I can’t find the problem, and also the script tp two players to same spawn point (name of spawnpoint is the name of mapa)
local maps = game.ReplicatedStorage.Maps
local gameTime = 90
local serverMessages = game.ReplicatedStorage.ServerMessage
local gameState = game.ReplicatedStorage.GameState
local choosenMap
local aliveFolder = game.ReplicatedStorage.PlayersAlive
local lobbyFolder = game.ReplicatedStorage.PlayersInLobby
local sword = game.ReplicatedStorage.Sword
local amt = 1
local RanMap = {“Crossroads”}
while true do
wait(1)
serverMessages.Value = "Waiting for more players"
repeat wait()until #game.Players:GetChildren() >= 2
serverMessages.Value = "Intermission"
local players = { }
game:GetService("Players").PlayerRemoving:Connect(function(plr)
table.remove(players,table.find(players,plr)
)
end)
for i,plr in pairs(game.Players:GetPlayers())do
if plr then
table.insert(players,plr)
end
end
local random = math.random(1,table.getn(RanMap))
choosenMap = RanMap[random]
wait(25)
serverMessages.Value = choosenMap … " was chosen"
wait(3)
local NewMap = maps[choosenMap]:Clone()
NewMap.Parent = workspace
NewMap.Name = “Map”
local Number
Number = 5
for i = 1,Number do
serverMessages.Value = "Joining in "… Number
Number = Number - 1
wait(1)
end
for i, plr in pairs(players)do
if plr then
local character = plr.Character
character:MoveTo(workspace:FindFirstChild("Map").Position)
end
end
for i,PlrValues in pairs(lobbyFolder:GetChildren())do
PlrValues.Parent = aliveFolder
end
serverMessages.Value = "Get Ready!"
wait(3)
Number = 1
for i = 1,Number do
serverMessages.Value = "Starting In ".. Number
Number = Number - 1
wait(1)
end
for i, plr in pairs(players)do
if plr then
if aliveFolder:FindFirstChild(plr.Name)then
plr.PlayerGui.Message.PlayersInMatch.Visible = true
local character = plr.Character
local NewSword = sword:Clone()
if not plr then
table.remove(players,o)
end
NewSword.Parent = character
else
end
end
end
gameState.Value = true
wait(1)
Number = gameTime
print(#players)
-- game timer
for i = gameTime,0,-1 do
for o,plr in pairs(players)do
if plr then
local character = plr.Character
if not character then
else
if aliveFolder:FindFirstChild(plr.Name) then
else
table.remove(players,o)
end
if workspace:FindFirstChild(plr.Name)then
else
table.remove(players,o)
end
end
else
table.remove(players,o)
end
end
serverMessages.Value = "Time Left ".. i .. " s"
if #players == 1 then
serverMessages.Value = players[1].Name.. " is the Winner"
players[1].leaderstats.Wins.Value = players[1].leaderstats.Wins.Value + amt
break
elseif #players == 0 then
serverMessages.Value = "Game Over"
break
elseif i == 0 then
serverMessages.Value = "Times Up"
break
end
wait(1)
end
gameState.Value = false
NewMap:Destroy()
for i, plr in pairs(players)do
if plr then
local character = plr.Character
character:MoveTo(workspace.Lobby.Position)
end
end
for i,PlrValues in pairs(aliveFolder:GetChildren())do
PlrValues.Parent = lobbyFolder
end
for i, plr in pairs(players)do
if plr then
plr.PlayerGui.Message.PlayersInMatch.Visible = false
local character = plr.Character
if character:FindFirstChild("Sword")then
character.Sword:Destroy()
elseif plr.Backpack:FindFirstChild("Sword")then
plr.Backpack.Sword:Destroy()
end
end
end
end
I already change map and spawn positions.