So i Have This map Voting Script And Works Fine, It Does Make You Vote Maps And When There’s a Tie Or Nobody Voted, It Randomly Picks The map For You, BUT There’s One Issue On it, And Its That It Just Stop Working Randomly And i Have This error Message.
ServerScriptService.MainMapVoteScript:36: attempt to index nil with ‘Value’
So What Is happening Here, Why Does It Randomly Stop Working?
wait()
local CustomWait = require(game.ReplicatedStorage.CustomWait)
local MapPicked = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mapsfolder = ReplicatedStorage:WaitForChild("Maps")
local booleans = ReplicatedStorage:WaitForChild("Booleans")
local variables = ReplicatedStorage:WaitForChild("Variables")
local choice1 = variables:FindFirstChild("Choice1")
local choice2 = variables:FindFirstChild("Choice2")
local choice3 = variables:FindFirstChild("Choice3")
local Winner = variables:FindFirstChild("Winner")
local timer = game.ServerStorage:FindFirstChild("Value").Value
while true do
local Maps = Mapsfolder:GetChildren()
choice1.Value = Maps[math.random(1,#Maps)]
table.remove(Maps,table.find(Maps,choice1.Value))
choice2.Value = Maps[math.random(1,#Maps)]
table.remove(Maps,table.find(Maps,choice2.Value))
choice3.Value = Maps[math.random(1,#Maps)]
table.remove(Maps,table.find(Maps,choice3.Value))
wait(1)
booleans:FindFirstChild("VotingSession").Value = true
wait(10)
booleans:FindFirstChild("RevealVotes").Value = true
wait(5)
booleans:FindFirstChild("VotingSession").Value = false
booleans:FindFirstChild("RevealVotes").Value = false
local Forcedchosenmap = variables:FindFirstChild("ForcedWinner").Value
local chosenmap = Winner.Value
local map = chosenmap.Value
if map then
local clonemap = map:Clone()
--
if not Winner.Value then
print("No Winners Picking Random")
game.ServerStorage.NameValue.Value = "No Winners, Picking Random Map..."
wait(1)
Maps[math.random(1,#Maps)]:Clone().Parent = workspace
end
print("Getting map...")
if variables:WaitForChild("MapPicker").Value == true then
game.ServerStorage.NameValue.Value = Forcedchosenmap.Name
else
game.ServerStorage.NameValue.Value = map.Name
end
wait(1)
print("Getting map spawn...")
if variables:WaitForChild("MapPicker").Value == true then
MapPicked = true
Mapsfolder:FindFirstChild(Forcedchosenmap.Name):Clone().Parent = workspace
else
clonemap.Parent = workspace
end
for i = timer , 0 , -1 do
if game.ServerStorage.EndValue.Value == true then
game.ServerStorage.Value2.Value = 0
game.ServerStorage.EndValue.Value = false
break
end
ReplicatedStorage.RoundValue.Value = i
game.ServerStorage.Value2.Value = i
CustomWait(1)
end
game.ServerStorage.NameValue.Value = "Choose a Map!"
--For Mpas That has npcs
for _,Model in pairs(workspace.NPCFolder:GetDescendants()) do
if Model:IsA("Model") then
Model:Remove()
end
end
for _,Model in pairs(workspace.PlayerNPCFolder:GetDescendants()) do
if Model:IsA("Model") then
Model:Remove()
end
end
ReplicatedStorage:FindFirstChild("StopSpectate"):FireAllClients()
if MapPicked == true then
MapPicked = false
variables:WaitForChild("MapPicker").Value = false
if workspace:FindFirstChild(Forcedchosenmap.Name) then
workspace:FindFirstChild(Forcedchosenmap.Name):Remove()
else
clonemap:Remove()
end
else
clonemap:Remove()
end
else
Maps[math.random(1,#Maps)]:Clone().Parent = workspace
end
end