Choice value not changing! (Attempt 3)

Hello!

I was working on a voting system for my game until I ran into a problem.

In ReplicatedStorage, there is a folder called Variables which contains variables.
The main ones being Choice1, Choice2 and Choice3.

The purpose of these values is to store the map names and then get taken by a LocalScript which then changes the map name text (In the vote GUI) to the map’s name.

But, whenever it tries to change the value, the value is still empty and therefore the text is just MapName.

Stuff (LocalScript in the Choice1,2 or 3 frames)
task.wait(10)

local Player = game:GetService("Players").LocalPlayer
local Voted = Player:WaitForChild("voted")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Votere = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("Vote")
local Variables = ReplicatedStorage:WaitForChild("Variables")
local Boolean = ReplicatedStorage:WaitForChild("Booleans"):WaitForChild("RevealVotes")
local Choice = Variables:WaitForChild("Choice1")
local VoteChoice = Variables:WaitForChild("VoteChoice1")
local VotesCounter = script.Parent:FindFirstChild("Votes")

local Map = Choice.Value
if Choice.Value then
	script.Parent.MapName.Text = Map.Name
end
Choice:GetPropertyChangedSignal("Value"):Connect(function()
	local Map = Choice.Value
	if Choice.Value then
		script.Parent.MapName.Text = Map.Name
	end
end)

if Voted.Value == true then
	script.Parent.Choice1.Visible = false
else
	script.Parent.Choice1.Visible = true
end

Voted:GetPropertyChangedSignal("Value"):Connect(function()
	if Voted.Value == true then
		script.Parent.Choice1.Visible = false
	else
		script.Parent.Choice1.Visible = true
	end
end)

script.Parent.Choice1.MouseButton1Click:Connect(function()
	Votere:FireServer(Choice.Name)
end)

if Boolean.Value == true then
	VotesCounter.Visible = true
	for i = 1,20 do
		VotesCounter.Text = "Votes: "..math.random(0,10)
		wait()
	end
	VotesCounter.Text = "Votes: "..VoteChoice.Value
else
	VotesCounter.Visible = false
	VotesCounter.Text = "Votes: "
end

Boolean:GetPropertyChangedSignal("Value"):Connect(function()
	if Boolean.Value == true then
		VotesCounter.Visible = true
		for i = 1,20 do
			VotesCounter.Text = "Votes: "..math.random(0,10)
			wait()
		end
		VotesCounter.Text = "Votes: "..VoteChoice.Value
	else
		VotesCounter.Visible = false
		VotesCounter.Text = "Votes: "
	end
end)
MainScript (Script in ServerScriptService)
-- torture time...

task.wait(10)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsFolder = game:GetService("ServerStorage"):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 = 10

while true do
	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 ChosenMap = Winner.Value

		if not Winner.Value then
			print("Something went wrong!")
			break
		end
		local Map = ChosenMap.Value
		local Clonemap = Map:Clone()

		print("Getting map...")
		wait(1)
		print("Getting map spawn...")
		if Clonemap.Spawn then
			print("Success!")
		else
			print("Task failed successfully")
			wait()
			print("Restarting...")
			Clonemap:Destroy()
			break
		end
		Clonemap.Parent = workspace
		print("Getting players...")
		local players = game:GetService("Players"):GetPlayers()
		for x, player in pairs(players) do
			local Character = player.Character
			if not Character then
				print(player.Name.." has no character!")
			else
				local HumanoidRootPart = Character.HumanoidRootPart
				if not HumanoidRootPart then
					print(player.Name.." has no HumanoidRootPart!")
				else
					HumanoidRootPart.CFrame = Clonemap.Spawn.CFrame + Vector3.new(0,3,0)
				end
			end
			wait()
		end
		for i = Timer, 0, -1 do
			print(i)
			wait(1)
		end
		for x, player in pairs(players) do
			local Character = player.Character
			if not Character then
				print(player.Name.." has no character!")
			else
				local HumanoidRootPart = Character.HumanoidRootPart
				if not HumanoidRootPart then
					print(player.Name.." has no HumanoidRootPart!")
				else
					HumanoidRootPart.CFrame = workspace.Lobby.LobbySpawn.TPPart.CFrame + Vector3.new(0,3,0)
				end
			end
			wait()
		end
		Clonemap:Destroy()
	end
end

Thanks! Waiting for a reply.

ok nvm i was stupid i just needed to change the Maps folder location in Lighting (it was in ServerStorage)

I’m not the one to call people stupid, but I…

When that is said, great to hear that you figured out the solution to your problem. :smiley:

If you want help with figuring out, how to stop the voting, when over half of the playing players have voted on the same choice, then just let me know.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.