I'm attempting to get votes from the client through the press of a button. To do so, I made a RemoteEvent which sends the text of the selected GUI to the server so the vote can be counted on the dictionary.
Every test for the above, I cannot print any keys or values of the table nor can I access the values even if I give the exact name of the key to print the value, I get nil.
--Server Script Votes = { ["Test1"] = 0, ["Test2"] = 0, ["Test3"] = 0, ["Test4"] = 0, ["Test5"] = 0, ["Test6"] = 0, ["Test7"] = 0, ["Test8"] = 0 } SendVote.OnServerEvent:Connect(function(Plr, V) print(V) Votes[V] = Votes[V] + 1 end)
-- local script (some code not displayed for it serves no purpose to display local GUI = script.Parent local Disable = false for _, v in pairs(GUI.ModeFrame.SecondaryFrame.Selections:GetChildren()) do v.MouseButton1Click:Connect(function() if not Disable then Disable = true ChangeText(GUI.ModeFrame.SecondaryFrame.Selection.Select, v.Text) SendVote:FireServer(v.Text) SelectionAnimation(GUI.ModeFrame.SecondaryFrame.Selections:GetChildren(), true) GUI.ModeFrame:TweenPosition(UDim2.new(0.5, -200, 1.2, -200), "Out", "Bounce", 1) GUI.ModeFrame.Visible = false end end) end
I'm able to print the memory location of the Dictionary (print(Votes)) within the SendVote chunk but if I were to run a loop through the Dictionary, I would get no output. Also, trying to access the value and increment it by 1 gives me an arithmetic error because Votes[V] is found to be nil.
I am unsure why this would not work, I feel I would have stumbled upon this issue in the past if the Remotes were unable to access a dictionary within a script or I am simply missing something dumb and do not see it currently.
EDIT The answer is I was doing something dumb. To answer my question, yes you can access a dictionary on a server script using a RemoteEvent. My issue was I cleared my Dictionary because it would have new values after a game, but I forgot I was using a dictionary and removed my keys as well, making a basic table that did not have the needed entries.
Something must be wrong with firing the event to the server when clicking the button. Maybe an error somewhere in the client script? I've tested it my self, and everything seems to be working fine.
Server:
--Server Script Votes = { ["Test1"] = 0, ["Test2"] = 0, ["Test3"] = 0, ["Test4"] = 0, ["Test5"] = 0, ["Test6"] = 0, ["Test7"] = 0, ["Test8"] = 0 } game.ReplicatedStorage.SendVote.OnServerEvent:Connect(function(Plr, V) print(V) Votes[V] = Votes[V] + 1 for _, v in next, Votes do print (v) end end)
Client:
-- Client wait(10) game.ReplicatedStorage.SendVote:FireServer("Test1")
Everything prints correctly.
Output:
Test1
0
1
0 (x6)