For loop won't work even though the exact same loop works on other scripts

Spawnplayers.OnClientEvent:Connect(function()
	task.wait(0.05)
	for _, v in pairs(workspace.CurrentMap:GetChildren()) do
		print(v.Name)
		currentmap=v--v is the map
		
	end
end)
obj.OnClientEvent:Connect(function()
	task.wait(0.05)
	if currentmap.Name=="Maze" then--error
		
		main.Visible=true
		main.Text.Text="Find the powerboxes and turn it on"
		num.Text=tostring(objnumvalue.Value).."/4"
		main:TweenPosition(UDim2.new(0.624,0,0.028,0), "Out", "Quad", 0.5)
		objnumvalue.Changed:Connect(function()
			num.Text=tostring(objnumvalue.Value).."/4"
		end)
	elseif currentmap.Name=="Backrooms" then--error
		main.Visible=true
		print("BACKROOMS OBJ RECIEVED")
		main.Text.Text="Find the generator and turn it on."
		num.Text=""
		main:TweenPosition(UDim2.new(0.624,0,0.028,0), "Out", "Quad", 0.5)

	end
	
end)
	

objcom.OnClientEvent:Connect(function()
	num.Text="OBJECTIVE COMPLETED."
	task.wait(1)
	main:TweenPosition(UDim2.new(0.624,0,-1,0), "Out", "Quad", 0.5) 
	main.Visible=false
end)

CurrentMap is a folder inside workspace that stores current maps that are used in the round.
remoteevents work fine, but the error was : Attempt to index nil with “Name”.

The loop works fine on serverscripts, and this is a localscript and the loop does not work. It also does not print (v.Name). So idk what should I do.

I suggest you use ipairs() when dealing with array tables, such as the returned value of :GetChildren(). Other than that, there doesn’t seem to be any noticeable errors.

Are you sure Spawnplayers is being fired?

That means “currentmap” which is v, does not exist. Check to make sure your spelling is correct or that the so called “currentmap” is under the workspace and inside of a model/folder/whatever you are using to store it. Else, you will get this error. It could also be getting destroyed or not loading properly, especially if you have StreamingEnabled set to true in the workspace. Once you select “Play” in the studio, your character will spawn. After you spawn, you will see a computer icon which says “Current: Client”. Click that and you will be able to see the game from the server’s viewpoint or, the way you would normally see it before clicking “Play” in the studio. After that, open the workspace and open whatever “currentmap” should be located. If it isn’t there, then that is your issue. If it is there, then there is either a spelling error or you may have left something out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.