Code issues - Voting system

Wouldn’t this code just keep adding to the value? What if they already voted and want to undo their vote?

The best way I could think of is adding an INT value to every player upon joining. Let’s say 0 == no vote, 1-3 == voted. In a local script containing the mouse events, you can fire a remote event TO the server with the parameter of what they voted for.

You want to check for server-side validation to make sure the vote is valid, and if it IS valid, you can toggle their vote.

Here’s a demo of what it looks like: vote.rbxl (27.5 KB)

Feel free to study how the voting system works. It’s incredibly simple.

This has a lot of flexibility since it is an actual instance value. After the voting ends, you can make ALL the player’s Vote value 0 and update the client.
It’s also not easy to exploit since it TOGGLES the client’s vote, so they can’t just spam a bunch of requests with one particular vote and expect it to keep increasing the vote count.

1 Like

Thank you very much, this worked … it is quite difficult to read the script but it will take me time to learn, thanks you a lot! :smiley:

Haha, I should’ve added more comments looking back on it, but if you need me to explain any particular line(s) of code, I would gladly help you out with that.