Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a map voting gui?

I have tried a video by HowToRoblox, And Unpurrity, Both do not work. Every other video i could find is about stepping on A fricken pad, that is useful for another game that i am making, but not for this one. Please get back to be ASAP with a video, Or code (and where to put it ofc) Thanks!:)

6 comments

0

rkh

0

Dont Come Here asking for Scripts. This site is called Scripting Helpers , Not "Scripting Givers".

0

Yeah, But that isnt helping because this is called scripting 'helpers'. can you just help in any way shape or form?

0

I can.

0

Learn to script this is not scripting teachers

0

I said I was going to give him some logic , and ended typing an essay.... silly me , I got too infatuated with this topic.

1 answer

I wont give you a script for it , I just give you some logic for it.

If you have a minigame Script and It gives you 3 Maps in Tables like this

local MapChoices = { ["First Map"] = {Map = "Ocean Map" , Votes = 0} 

  ["Second Map"] = {Map = "Forest Map" , Votes = 0} 

" ["Third Map"] = {Map = Desert Map" , Votes = 0} }

You can Now Reference the Tables By now saying MapChoices.FirstMap -- which will return a table or

MapChoices.FirstMap.Map-- Which Will return the Name of the Map or...

MapChoices.FirstMap.Votes-- Which Will return the amount of votes of the Map

{NOTE , You also could use math.random() To randomize the maps , if you have more than this!)

Then To Count The Votes You could create a Table Like This


You could then Possibly use the FireAllClients(MapCHoices) and send all of the Map Choices to all of the Clients.

Then You could use Remote.OnClientEvent(Maps) To have the Client Recive those maps inside the parameter.

once the Client recives thoese maps , The Gui can Pop Up. You would Probably then use a for i,v loop on all of the Buttons , [Im going to assume you have 3 Buttons , Named Button1 , Button2 , Button3]

You Can Make a MouseButton1ClickEvent for Button1 to Fire The Server to Send back The Vote for the Maps.FirstMap.Map like This SomeRemote:FireServer(Maps.FirstMap.Map)

Then , You Can Make a MouseButton1ClickEvent for Button2 to Fire The Server to Send back The Vote for the Maps.SecondMap.Map like This SomeRemote:FireServer(Maps.SecondMap.Map)

and So on for the 3rd One.

Once the Client Has Fired the Server Back with the use of FireServer(TheMapYouVotedFor)

the Server Can Doe A for i,v loop

It will Loop though The Table of Map Choices and See if the Name of the Map you voted for is the same of the map value the table if on.

It would Look like this...


local SomeConnection

SomeConnection = SomeRemote.OnServerEvent:ConnectFuntion(TheMapYouVotedFor)

for i,v in pairs(MapChoices) do

--// If it matches the Map you voted for... then

if v.Map == TheMapYouVotedFor then

v.Votes = v.Votes + 1

else
--// Dont do anything. Leave it the value alone... !

end

end



end)

if it matches the Name , then the Votes go Up by 1, else dont do anything because you have not voted.

You then could add some 10 second wait if you want to. THen after 10 seconds , end the voting , by disconnecting the Connected that was used on whatever vote connection you were using

(You could also make so that in 10 seconds , the Gui would disapear with a simple

--// On The Client Side!

spawn(function()
wait(10)
Gui.Eanbled = false

--// or Frame.Visible = false (If your UI is a frame!)
end

)

At the end of 10 seconds , make the server created a variable called local MostVotedMap , MostVotes = nil , 0 --- A Place holder Value for the Most Voted Map!

Then Make A Table called local TiedMaps = {}--- A Table for storing Maps that were tied in votes!

Run a for i,v in pairs loop through the MapChoices

Then Compare the Maps Votes With thenMostVotes Value to see if it is higher then MostVotes. If it is higher , then Overwrite the MostVotes Value to the Value of the votes that map has , like this :

--// Inside the SomeRemote.OnServerEvent Event
--// Inside a Server Script


for i,v in pairs(MapChoices) do

if v.Votes > MostVotes then

MostVotedMap = v.Map
MostVotes = v.Votes

else

--//if The First Map 'Ocean Map' had 3 votes  and changed the MostVotes Value from 0 to 3 
--// then Second Map 'Forest Map' Map had 1 vote , then the loop would see that v.Votes(1) < MostVotes(3) and will not overwrite the Most Votes.

end


end

--//Put MostVotedMap in Tied Maps , just incase It tied with another Map !
table.insert(TiedMaps , MostVotedMap)

Next Run Another for i,v in pairs loop to find out if any other map votes tied with the MostVotes like this


--// Inside the SomeRemote.OnServerEvent Event
--// Inside a Server Script

for i,v in pairs(MapChoices)

--// If this Map's Votes were equal to the MostVotes and it is not The MostVoted Map , then.
if v.Votes == MostVotes and v.Map ~= MostVotedMap then

table.insert(TiedMaps , v.Map)

end

end

Now To check if we have any tied Maps , We can check how many entries are inside the Tied Map Table , like this :

if table.getn(TiedMaps) > 1 then

then lets pick a random map out of the tied Maps Like this ....


--// Inside the SomeRemote.OnServerEvent Event
--// Inside a Server Script

if table.getn(TiedMaps) > 1 then

local RandomMap = TiedMaps[math.Random(1,#TiedMaps)]

local ChosenMap = RandomMap

--// Disconnect SomeConnection Here like this "SomeConnection:Disconnect()"

end

And Boom !

Now We Have the ChosenMap . This Variable is a String and You can use it to reference a map that is in a folder somewhere in the game that is probably a model

local Map = game.ServerStorage.Maps[ChosenMap]--// The Actual Map Model (This is --//assuming you have a Map Folder in Server Storage !

There We go , we should have a nice voting UI

It took me a while to write this , and I did not Test it. In fact , It is the First Map voting script I have ever written purely from logic.

Embrace this knowledge , For Roblox Lua is a long Journey , or any COding Language for that matter.

Have a Good Day xsmoothlyx

--// T40

:D !

This discussion is preserved as it was. New answers, comments, and votes are closed.