Forcing map returns a nil?

  1. What do you want to achieve? I want to achieve forcing the map selection to select map.

  2. What is the issue? When setting the ForcedMap value to a name of a map, it tries to find the certain map but fails, returning nil.

  3. What solutions have you tried so far? I looked in Developer Hub and DevForum but didn’t find anything to solve my problem.

Here’s the code below.

local MapsFolder = game.Lighting.Maps
local Maps = MapsFolder:GetChildren()
local RoundTime = script.RoundTime
local Music = script.Parent.Music
local RemainingTime = script.TimeRemain
local HUDMap = script.CurrentMap

while true do
	HUDMap.Value = "loading map"
	local ChosenMap = Maps[math.random(1,#Maps)]
	if script.ForcedMap.Value ~= "" then
		ChosenMap = table.find(Maps, script.ForcedMap.Value) --this i think
		script.ForcedMap.Value = ""
	end
	local MapClone = ChosenMap:Clone()
	MapClone.Parent = game:GetService("Workspace")
	MapClone:MakeJoints()
	for num,player in pairs(game.Players:GetPlayers()) do
		player:LoadCharacter()
	end
	HUDMap.Value = tostring(ChosenMap.Name)
	RemainingTime.Value = RoundTime.Value
	while RemainingTime.Value >= 0 do
		wait(1)
		RemainingTime.Value -= 1
	end
	HUDMap.Value = "loading map"
	MapClone:Destroy()
	MapClone = nil
end
ChosenMap = Maps:FindFirstChild(script.ForcedMap.Value)

Already tried that, doesn’t work.

script.ForcedMap.Value

Because this is a StringValue instance and the variable named “Maps” is an array of instances (I presume they are models which are the different maps), you can’t use table.find() to find an instance in an array when you’re searching that array with a string value.

StringValue, it is.
How am i otherwise going to force a map?

Yes, I figured it was a StringValue instance, I was editing the post when you replied. An ObjectValue instance would still be valid, it seems that whatever names you’ve chosen for your map are not matching whatever value is stored inside that StringValue instance.

I’ve found the solution, turns out I had to use a ObjectValue because of a StringValue. Thanks!