I need help with this code

Hey guys I need Simple Help on this Code

image

You can see here a code for random map selection

What I need is there’s way to make the code Choose the map I want instead of the random selection?

Hope you Help me!

If you know the name of the map, you can do

local MapName = "TheMapNameYouWantToChooseHere"

local ChosenMap = MapsFolder:FindFirstChild(MapName)

--// Then you can check like

if ChosenMap then
   print("Map found")
else
   print("Map does not exist")
end

Edit: Fixed code error, thanks @AridFights1 for the catch

1 Like

can you specify? if what you want is a map selection system you need many more things

image

hmm… It’s still didn’t work

I don’t need map selection system

All I need is choosing map with the name instead of the random selection

Check the 1st reply to this post. That’s the solution. All you need to do is change the string to the map name you want.

Edit: I did found a mistake in the code of that reply. Here’s the fixed one:

local MapName = "TheMapNameYouWantToChooseHere"

local ChosenMap = MapsFolder:FindFirstChild(MapName)

--// Then you can check like

if ChosenMap then
   print("Map found")
else
   print("Map does not exist")
end

If you, for example, want to select a map via a GUI or command line from the client you need a RemoteEvent for this. This is mainly because you might want to change the map while playing instead of hardcoding it with a variable.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = nil --you can set this to a default map if you want

RemoteEvent.OnServerEvent:Connect(function(MapName) --executes this function when the event is fired from the client
        ChosenMap = AvailableMaps[MapName]
        --do the rest of your code here if you need to
end

Keep in mind this can be abused by exploiters if they have access to whatever you have planned for a map selection from the client, you may need to do some changes if that is the case.

1 Like

Thanks you so much It did work!

2 Likes

Ain’t no problem mate! We all make mistakes, and that’s how we grow!

1 Like

Thanks for the Help @https_KingPie

1 Like