I have made a voting system for a story type game. The player goes down the road and has to choose which path they take. The good thing about this system is if I get it to work I can just keep calling it in the server with different values for different votes. After they vote the value is supposed to be sent to the server for the NPC to say which direction they are going.
Server (only relevant code) :
local rStorage = game:GetService("ReplicatedStorage")
local rEvents = rStorage:WaitForChild("Events")
local votewinner = ""
local NPCs = workspace.NPCs
rEvents.DialogueVisible:FireAllClients(false)
rEvents.VoteEvent:FireAllClients("Which way should we go?", 2, 10, "Left", "Right")
wait(10)
rEvents.VoteResults.OnServerEvent:Connect(function(player, winner)
if winner == 1 then
votewinner = "left"
end
if winner == 2 then
votewinner = "right"
end
rEvents.DialogueVisible:FireAllClients(true)
rEvents.Dialogue:FireAllClients(NPCs.John, "Looks like we are going ".. votewinner.. ".")
end)
Local (only relevant code):
rValues.Vote2.Changed:Connect(function()
clone2.Counter.TextLabel.Text = rValues.Vote2.Value
print(rValues.Vote2.Value)
end)
wait(votetime)
if rValues.Vote1.Value > rValues.Vote2.Value then
winner = clone1.Name
print(winner)
end
if rValues.Vote2.Value > rValues.Vote1.Value then
winner = clone2.Name
print(winner)
end
if rValues.Vote1.Value == rValues.Vote2.Value then
local randomOptions = {clone1.Name, clone2.Name}
local RandomResult = math.random(#randomOptions)
for i=1, 1 do
winner = winner..randomOptions[RandomResult]
end
print(winner)
end
rEvents.VoteResults:FireServer(player, winner)
script.Parent.Visible = false
wait()
removeChoices()

1 comment
Isn't everything below line 4 suppose to be inside your .Changed:connect