Whoever has answered/saw my questions, here is the reason for all of those. I'm making a voting gui that sees if players think the server is broken. When they vote yes/no, their name is added to the table so they cannot vote again. What is wrong with my script? There's no output errors.
voted = {} plr = script.Parent.Parent.Parent.Parent script.Parent.NoBttn.MouseButton1Click:connect(function() for x, e in pairs(voted) do if not plr.Name == e then table.insert(voted, 1, plr.Name) for b = 1,1 do Val2.Value = Val2.Value + 1 end end end end)
It seems to be getting stuck at the generic for.
local voted = {} local plr = script.Parent.Parent.Parent.Parent script.Parent.NoBttn.MouseButton1Click:connect(function() if not voted[plr.Name] then voted[plr.Name] = true Val2.Value = Val2.Value + 1 end end)
Give this a try.
It looks like this is in a LocalScript in which case this could be implemented much more simply. However, if it is in a LocalScript, it will be recreated with the player when they respawn, allowing the player to vote again.
Here is a more robust method of counting votes and disallowing multiple votes from the same player:
Create a Script object in ServerScriptService and put this code in it:
local voted = {} local playerVote = Instance.new("RemoteFunction") playerVote.Name = "PlayerVote" playerVote.OnServerInvoke = function(player, vote) if not voted[player] then voted[player] = true if vote then --Add a "Yes" vote --TODO - Add your code here for counting a "Yes" vote. Maybe increment the value of Val1? else --Add a "No" vote Val2.Value = Val2.Value + 1 end end end) playerVote.Parent = workspace
Create a LocalScript object as a sibling to the Yes and No buttons containing this code:
local playerVote = workspace:WaitForChild("PlayerVote") --connect "No" button to handler script.Parent.NoBttn.MouseButton1Click:connect(function() playerVote:InvokeServer(false) end) --connect "Yes" button to handler script.Parent.YesBttn.MouseButton1Click:connect(function() playerVote:InvokeServer(true) end)
I might not be correct, but I am pretty sure that since there is no one in the table it cannot do a loop. Also since 1 is already 1 it cannot make the value change. Though I may be wrong. For the second for loop I would suggest:
for b=0,1 do Val2.Value=Val2.Value+1 end
and I would add a name in the table. Not a real name but one that you could remove after a player votes or just say if the name~="guesty" then ...