Attempt to index nil with 'Clone'

Anyone can help me with this error?. I have tried a lot of things still I can’t fix it.

local button = script.Parent
local service = game:GetService("Players")
local humanoid = service.LocalPlayer.Character:WaitForChild("Humanoid")
local Players = game:GetService("Players")

local siyahgui = game.Players.LocalPlayer.PlayerGui.gui2.policenendingsiyah

local map = game.ReplicatedStorage:WaitForChild("Map")

button.MouseButton1Click:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Players = game:GetService("Players")

	local function anchorCharacters(anchor, list)
		for _, player in pairs(Players:GetPlayers()) do
			local character = player.Character

			if character then
				if list then
					table.insert(list, character)
				end

				character.PrimaryPart.Anchored = anchor
			end
		end
	end
	

	
	local function loadMap(map)
		local blacklist = {}
		anchorCharacters(true, blacklist)

		for _, child in pairs(workspace:GetChildren()) do
			if not table.find(blacklist, child) then
				if not child:IsA("Terrain") then
					child:Destroy()
				end
			end
		end
		
		local clone = map:Clone()
		clone.Parent = workspace

		anchorCharacters(false)
	end
	
	loadMap()
	
	siyahgui.BackgroundTransparency = 1
end)

2 Likes

Errors saying Attempt to index nil with means that something (in this case the thing that you are trying to clone; Map) is nil (does not exist)

Check if there is a thing called Map in ReplicatedStorage (capitalization matter)
and if there is, other scripts may be destroying the map.

Im sure there is a Map Folder in ReplicatedStorage, and i checked the folder while testing game. Nothing destroys the map

Can you print(Map.Name) or something to make sure that it’s actually there?

i did and there is “Map” in output

Hello, instead of printing “Map.Name”, you should print “Map.Parent”, this way you can see where is your map located at and change the path that lead to it in your script.

Hey! You dont set map variable when calling function loadMap()!

1 Like

I meant, you have 2 variables in function, Global Variable Map and Map Variable that providing function, so you need to change name of one.

3 Likes

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