-- define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local Gamelength = 50
local reward = 25
-- gameloop
while true do
Status.Value = "Waiting for enough players..."
repeat wait(1) until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(10)
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) -- Add each player in plyrs table
end
end
wait(2)
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)] -- random map
Status.Value = ChosenMap.Name .. " Map Chosen"
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
-- determines if there is a SpawnPoint
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print ("SpawnPoints not found!")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleports Player
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
table.remove(AvailableSpawnPoints,1)
-- Give them a Sword
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
-- GameTag
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- There is no character
if not player then
table.remove(plrs,i)
end
end
end
end
Status.Value = "Get ready to Play!"
wait(2)
for i = Gamelength,0 -1 do
for x,player in pairs(plrs) do
if player then
character = player.Character
if not character then
-- they left the game
else
if character:FindFirstChild("GameTag") then
-- they are still alive
print(player.Name .. " is still in the game")
else
-- they are dead
table.remove(plrs.x)
print(player.name .. " has been removed!")
end
end
else
table.remove(plrs.x)
print(player.name .. " has been removed!")
end
end
Status.Value ("There are " ..i.. " seconds remaining and " .. #plrs .. " players left")
if #plrs == 1 then
-- Last Person Standing
Status.Value = "The winner is " .. plrs[1].Name
plrs[1].leaderstats.Cash.Value = plrs[1].leaderstats.Cash.Value + reward
break
elseif #plrs == 0 then
Status.Value = "Nobody Won!"
break
elseif i == 1 then
Status.Value = "Timer ran out!"
break
end
wait(1)
end
print ("End of Game!")
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if not character then
-- Ignore Them
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
if character:FindFirstChild("Sword") then
player.Backpack:Destroy()
end
if character:FindFirstChild("Sword") then
character.Sword:Destroy()
end
end
player:LoadCharater()
end
ClonedMap:Destroy()
Status.Value ("Game ended")
end
COMMUNITY QUESTION
The player won't teleport to the spawn point, at a designated map inside a folder ??
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
https://stackoverflow.com/questions/12153537/error-attempt-to-index-field-a-nil-value
That is because AvailableSpawnPoints seems to be nil, maybe try using GetDescendants() Instead of GetChildren() on line 59, its also good because it returns a table with all the actual children of that instance.
oh that's quick Thanks! Igoralexeymarengobr & whenallthepigsfly
yeah AvailableSpawnPoints is still nil although in the map they exist Idk why the code can't find it..
Ah, gotta love this alvinblox code.