I fount a bug and I am in the process of fixing it.
THE BUG HAS BEEN RESOLVED ENJOY YOUR VOTING MODULE NOW~
Edit: I am hoping to rewrite this from scratch with a better API. I will do it once I have time.
EDIT: NUMBEROFVOTES THING HAS BEEN ADDED GO CHECK THE VOTING GAME TO TEST
EDIT: MODULE IS NOW OPEN SOURCE DUE TO PRIVATE MODULES NOT WORKING ANYMORE
https://www.roblox.com/library/4985345430/Voting-Module-v2
This module is under the license you can use my module for commercial purposes for free but not redistribute the source code.
Before we talk let me say this: This is a general-purpose voting module if you feel it is not I think I might have explained it wrong so please say something in the dev forum reply in this thread.
Hello, guys! I decided to make a better voting module and also make better documentation, so here I present Voting Module v2! Before let me explain the difference to the one. This VotingModule disconnects the event when you call VotingModule.EndVoting! So basically it is more efficient since it automatically disconnects events for you when you call a function. Also, I removed and added some new functions. Most importantly, I made a big change to the parameters! Before you had to specify parameters again and again, but now you know what you can do?!
FruitVoting = VotingModule.StartVoting(3,game.ServerStorage.Fruits, game.ServerStorage.VotingSystem.VotingFruitPads)
SportVoting = VotingModule.StartVoting(2,game.ServerStorage.Sports, game.ServerStorage.VotingSystem.VotingSportsPads)
VotingModule.EndVoting(SportVoting)
VotingModule.EndVoting(FruitVoting)
VotingModule.StoreVoting(SportVoting)
VotingModule.StoreVoting(FruitVoting)
Yep, now it’s better! The StartFunction returns a table and the module uses that table sent as an argument for its parameters if your wondering!
Anyways let’s get to the juicy part the documentation and the testing game.
Testing game link, also you can view its code in Roblox studio.
https://www.roblox.com/games/4990285664/Voting-Test
Documentation:
VotingModule.SetupVoting(NumberOfVotingOptions,FolderWithAllVoteOptions,VotePadsFolder)
NumberOfVoting Options is the number of voting choices that will be presented to the player
FolderWithAllVoteOptions is the folder with all the voting choices.
For example, if we were talking about maps it would be the folder with all the game’s maps!
In the case of Maps, it would store the Maps which will be used this round for voting.
We do not want to overwhelm the player with too many choices so we give him/her a certain amount of choices.
The Map’s info folder is where its image is located
That Image texture will be copied to the votingPad’s Essential.ImagePart.Image.Texture
VotePadsFolder is the VotePads you want to use which will correspond with the voting choices
The VotePadsFolder should contain the number of voting options declared by NumberOfVotingOptions
Remember you can set up multiple voting pads and have how many choices you want!
This function also makes the votepads presented as the argument inside the workspace to put the voting room to after this or before it uses the function VotingModule.DisplayVotingRoom()!
VotingModule.StartVoting returns a table of parameters passed in which can be used for other functions as the argument.
Alright StartVoting activates the touched events for the pads, basically activates voting
Also, it fires a remote event called VotingHandler in replicated storage with two pieces of info the votepad touched and the folder with votepads, I use this to make the pad green when touched in the voting test game. It fires it to the player who touched it.
For the ones below use the value returned by StartVoting as those function’s parameters, do this for everything except CleanUpVoting and the other two extra functions, DisplayVotingRoom and StoreVotingRoom() these take no arguments
VotingModule.VoteChoosingFunction()
Returns the choice with most votes at the present moment
VotingModule.EndVoting()
returns nothing
It ends voting disconnecting touched events
VotingModule.StoreVoting()
Stores the votepads folder inside the voting system in server storage again.
VotingModule.CleanUpVoting()
Removes all the values created in the player and etc by the voting system, PLEASE USE THIS after every voting cycle
The other Functions:
VotingModule.DisplayVotingRoom()
Makes the voting room model or folder in the VotingSystem folder in the server storage parented to the workspace. If you don’t have a voting room don’t use this because it will error obviously. In the test game, we have this.
same goes with:
VotingModule.StoreVotingRoom()
This parents it back to the folder VotingSystem in server storage
If you have any questions please ask me also any bugs please report them. Also if the voting module loader isn’t working in your game please say so, also give feedback. Also, Some things planned out is for the remote event fired in VotingModule.StartVoting I am going to include a voting state variable for further control for developers. And most importantly have fun!