I got problem with Loading Map in

Hi my names are Pixeluted and I want to do Who map win then load but I got error Here is a screenshot with error and script

Thank for read

2 Likes

It’s hard to understand what’s wrong, what would you like us to help you with?

I setting Value where is Name of map then I do load map but I got errorsome bad argument

“NameMap” is a nil value. Check if it’s there and if it’s a string and then proceed to index.

Something Like:
if NameMap and type(NameMap) == “string” then

— Code

end

What Please I do not understand ?

So I do if is here then print yes if no print no but its printed nothing Screenshot by Lightshot

The variable “NameMap” is nil. Check if it’s not nil and then proceed to index. That’s why it’s saying “string” expected got nil, because usually you index strings out of dictionaries and especially in this case you want to index a child of “Maps” which is indexed through its string Name

I now do value is Map but still saying nil Why ?

Check with an if statement to see how it goes.

If I do print then its print nohting its like skiping this is lines of script

game.ReplicatedStorage.Text.Value = "Map "..MapWin.Name.." won."
			workspace.VotingPads.Map1.SurfaceGui.Enabled = false
		workspace.VotingPads.Map2.SurfaceGui.Enabled = false
		workspace.VotingPads.Map3.SurfaceGui.Enabled = false
		script.Voting.Value = false

I know why because its skipping lines of script so Value can’t be created thats why saing it nil But I don’t know why its skipping this is lines of script

Because there is an if statement prior to it, if that statement condition isn’t met it’s never set. Which isn’t something you want.

What’s the ‘Map’ variable set to? It looks like it’s probably skipping over the entire if statement because Map isn’t “Map3”

2 Likes

Its voting I got only one map so I voting for map3 so if map3 win I want load it

But what is it set to? Are you sure ‘Map’ is actually set to the right value?

2 Likes

Everyone I fixed it Its be because I do wrong voting

1 Like

Why don’t you name your map names, randomize the index (as selection) and clone from there?

Looks something like this:

-- Server Script
local replicatedStorage = game:GetService("ReplicatedStorage")
local mapsFolder = replicatedStorage:WaitForChild("Maps")
local assetsFolder = workspace:WaitForChild("Assets") -- where map is stored once cloned

function changeMap()
	-- Remove old map if valid
	if #assetsFolder:GetChildren() > 0 then
		for _,v in pairs(assetsFolder:GetChildren()) do
			v:remove()
		end
	end
	
	local rand = math.random(1,#mapsFolder:GetChildren())
	for i,v in pairs(mapsFolder:GetChildren()) do
		if i == rand then
			v:Clone().Parent = assetsFolder
		end
	end
end

Use case:

-- Changes the map every second twenty times. 
local x = 0
repeat wait(1) print("New map") changeMap() x = x + 1 until x == 20

Sir what I do not understand your script Can you explain