Module Error, Attempt to Index Number With String [SOLVED]

I want to set a GUID in a table equal to a character object.

My Error

ServerStorage.npcModule:56: attempt to index number with 'A2C131BF-B437-4B94-B74B-1752FEF6D386'

How I’m doing it:

for npcs = 1, amount, 1 do
		local Player = plrFriendsArray[math.floor(math.random(1, plrFriendCount))]
		local id = generateId()
		local Char = getCharacterFromId(Player)
		print(Char)
		npcs[id] = Char
		Char.Humanoid.WalkSpeed = 100
		Char.Parent = game.Workspace
		Char.Name = Players:GetNameFromUserIdAsync(Player).." (NPC)"
		local currentLocation = nil
		if(lastLocation == nil) then
			currentLocation = CFrame.new(location)
			lastLocation = currentLocation
		else
			currentLocation = lastLocation * CFrame.new(-1 * (spacing), 0, 0)
			lastLocation = currentLocation
		end
		Char.Head.CFrame = currentLocation
		table.insert(arrayOfNPCs, id)
	end

Thank you ahead of time for helping to fix my issue.

npcs is being used as your iterator variable, so the line npcs[id] = Char is indexing a number, not a table. Have you created a table upscope named npcs that you have unintentionally shadowed?

1 Like

Thank you! I probably wouldn’t have noticed it without your help.

1 Like

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