Why Does This Map Vote Randomly Stop Working

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

I don’t think it “randomly stops working”? Your time 35 and 36 are the wrong here.
35: You’re taking a Value property from Winner object
36: You’re taking a Value property from object, which isn’t any Value based object, so doesn’t have Value property

1 Like

First of all, please, could you use task.wait() instead of wait()? wait() is deprecated and slower than task.wait(). By the way, avoid using :Remove(), and use :Destroy() instead as :Remove() is deprecated.

The script is failing at the line 36 because you’re trying to get the value of a BaseValue that doesn’t exist. Could you maybe try checking that script out for any lines that remove the value, or maybe other scripts?

1 Like

try replacing the code above with this:

local map = chosenmap
1 Like

it broke the entire script oof

whats in this modules customwait

its from this Forum

its because of this here you can setting chosemap to the actual map not the winner object value
so on the next line when you do chosenmap.Value its trying to check the actual map for Value property which is not there

the way the error reads it maybe only happening when a map is not chosen

1 Like