Stuck on Loading a Map that is Selected via Map Voting

Hi,

I have a map voting system in place but I’m having trouble with loading the associating map that’s voted, and I have no idea how to move forward. I initially used AlvinBlox’s tutorial as inspiration, but his code uses randomness for selecting maps. My one, however, is decided through votes by players via the touch event, or the game picks randomly (in the case of a tie).

That said, I want my script to draw a map model (child) - with its correlating MapName - from the “Maps” folder in replicated storage, is cloned, retains its map name for multi-round use, and is then parented to the workspace. I’m aware that I need to destroy this model for it to be returned to replicated storage to flow with a round-based system; I just need help with having it in the workspace in the first place. This is as transparent as I can be because I really have no idea what I’m doing LOL.

  -- ... 
local HighestVoted
	for i, Pad in pairs(Pads:GetChildren()) do
		if not HighestVoted then HighestVoted = Pad end
		
		if #Pad.Votes:GetChildren() > #HighestVoted.Votes:GetChildren() then
			HighestVoted = Pad
			
		elseif #Pad.Votes:GetChildren() == #HighestVoted.Votes:GetChildren() then
			local MapsToChoose = {Pad, HighestVoted}
			HighestVoted = MapsToChoose[math.random(#MapsToChoose)]
		end
	end

    local MapName = MapBoards["Map".. string.gsub(HighestVoted.Name, "MapVote", "")].MapGUI.MapName.Text

	local Maps = game.ReplicatedStorage.Maps:GetChildren()
	local ChosenMap = -- MapName variable here, etc. (Help here... after players voted for a particular MapName, the associated map model with the same name is selected from the Maps folder)
	local ClonedMap = ChosenMap:Clone()
    ClonedMap.Name = -- (Help here... example of a map name: "Haunted Mansion") 
	ClonedMap.Parent = game.Workspace

-- ...	

Any input is appreciated. :grin:

1 Like

Try printing a chosenmap after you made a chosenmap value. If it prints nil several times. It might be that you didnt set a chosenmap

Putting Maps[MapName] as the ChosenMap value, the output returns “attempt to index nil with ‘Clone’”.

Any advice on how to make the ChosenMap value relate to MapName?

You cant clone a nil value! So thats why it returns nil!

This line, you didnt tell the script to set any value so I think you must change this line

Perhaps I wasn’t clear…

	local Maps = game.ReplicatedStorage.Maps:GetChildren()
	local ChosenMap = Maps[MapName]
	print(ChosenMap)
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = game.Workspace

Result:

Im pretty sure the line [“Map”… string.gsub(HighestVoted.Name, “MapVote”, “”)].MapGUI.MapName.Text requires only a number?

This is my map-voting system running; there is no number required in the line for it to work

1 Like

Can i see where the maps are stored?

Try this:

local ChoosenMap = game.ReplicatedStorage.Maps:FindFirstChild(votedmapname)
ChoosenMap.Parent = game.Workspace

Thanks for the solution.

Just a side note: I replaced votedmapname with MapName and it’s all working now

Cheers

1 Like