Storing votes per player

Hello everyone,

This is my first post on here. I’ve been looking for hours and hours, but I can’t seem to understand something and I hope you can help me.

I am creating a map voting system. I already have the part working where the server selects 3 available random places and displays them. The player then clicks one to vote for it, and through a remote event things start happening. But I can’t for the love of me figure out what the best way is to store those votes. I’ve tried tables, dictionaries, even objects with custom attributes. I want to store it serverside.

So my apologies if this is a ‘stupid’ question, but how to go about this? So basically what I want is:

  • User clicks map
  • Player ID & MapID get stored somewhere (preferably a unique value, so player can’t exist twice, but I can handle that myself, once I understand how to store them.)

And that’s basically it. I already have a system (A number value for map1, map2 and map3 in serverstorage) that keeps track of the total votes.

The reason I want to store the Player + the map choice is for when they change their mind and select another map. In that case I need to change the value.

Just in case you do show a script snippet, please be so kind to show it for 2 or more players, because that’s where I get stuck.

I hope I’m making sense here, and if anyone could help I’d be eternally grateful.

Thank you!

1 Like

You should store the votes in a dictionary.

{
["GoodMap"] = 4,
["BadMap"] = 0
}

where the number represents the number of votes. The player should be store in a dictionary indexed by the player’s instance:

{
[Player1] = "GoodMap",
[Player2] = "GoodMap",
[Player3] = "GoodMap",
[Player4] = "GoodMap"
}

where it stores the name of the map they selected. When they change their mind, the script will index that dictionary with the player and remove a vote from the map previously in that dictionary. Then, it will update the 2nd dictionary with the new map that was just chosen by them, additionally adding a vote to the map they chose.

2 Likes

Thanks a million! This was exactly what I was looking for.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.