Hello, I am making a voting system and the map chosen is the highest number of votes the pad is. (Hopefully that made sense lol) Anyways, I keep getting this error while cloning it: Attempt to index nil with Clone. Does anyone know how to fix this? Thanks. Here is my current code:
local RS = game.ReplicatedStorage
local SS = game.ServerStorage
local intermission = game.StarterGui.Round.Intermission.Frame.IntermissionText
local text = game.StarterGui.Round.Intermission.Frame.TimeText.Text
local Maps = SS:WaitForChild("Maps")
local Status = RS:WaitForChild("Status")
local function CalculateWinner()
local padvotes = {
["Pad1"] = tonumber(workspace.Lobby.Radioactive.SurfaceGui.TextLabel.Text),
["Pad2"] = tonumber(workspace.Lobby.City.SurfaceGui.TextLabel.Text),
["Pad3"] = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text),
}
local highest = 0
local pad = nil
for i, v in pairs(padvotes) do
if v > highest then
highest = v
pad = v.Parent.Parent.Parent
end
end
return pad
end
while true do
--intermission.Text = "Waiting for enough players! (1/2)"
--repeat wait() until game.Players.NumPlayers >=2
intermission.Text = "Intermission:"
for i=1,10 do
wait(1)
local new = tonumber(text)-1
text = new
end
local plrs = {}
for i,player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) --add plr
end
end
local AvailableMaps = Maps:GetChildren()
local winner = CalculateWinner()
local ChosenMap = winner
local ClonedMap = ChosenMap:Clone()
ClonedMap:Move(CFrame.new(492.464, 54.5, -4.053))
ClonedMap.Parent = workspace
wait(2)
intermission.Text = "Game starting!"
wait(2)
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
warn("No spawnpoints found")
end
local AvailableSpawns = SpawnPoints:GetChildren()
for i,player in pairs(plrs) do
if player then
local char = player.Character
if char then
char:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawns[1].CFrame + Vector3.new(0,2,0)
table.remove(AvailableSpawns,1)
else
if not player then
table.remove(plrs,i)
end
end
end
end
end