830008x
(830008x)
June 1, 2023, 2:10am
#1
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
830008x
(830008x)
June 1, 2023, 3:25am
#3
Thank you! I probably wouldn’t have noticed it without your help.
1 Like
system
(system)
Closed
June 15, 2023, 3:26am
#4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.