Key From ModuleScript Returning nil but Exists

  1. What do you want to achieve?
    Anytime a script tries to grab the data for a specific enemy it returns nil, but the enemy is in the ModuleScript.

  2. What is the issue?


    The enemy is really far down the ModuleScript, but it’s defined like every other enemy and those work fine. I generated the ModuleScript with another programming language so I know there isn’t any typos.

  3. What solutions have you tried so far?
    Grabbing a different key from the enemy, same error.

Code to the script:

local function ChooseRandomZombie()
	local Type
	local Zombie
	
	while Zombie == nil do wait()
		Type = ChooseRandomChild(Zombies)
		local ZombieChosen = ChooseRandomChild(Type)
		if ZombieChosen then
			print(ZombieChosen.Name)
			local Rarity = EnemyStats[ZombieChosen.Name]["Rarity"]
			if math.random(1,Rarity) == 1 then
				Zombie = ZombieChosen
			end
		end
	end
	
	return Zombie:Clone(), Type.Name
end
1 Like

Can you show how you’re adding a key for the zombie’s name to EnemyStats?

1 Like

24352345Capture

1 Like

That’s what I did in the image in the post.

1 Like

Are you sure your zombie’s name is exactly “Reaper” (casing is correct, there’s no whitespace?

Can you also add a print(ZombieChosen.Name == "Reaper") and see if that’s true?

1 Like

Aight found it, you did a typo, you accidentally named the thing Repear instead of Reaper :skull:

1 Like

Where’s that at? I can’t find it.

1 Like

The typo is in the model name.

1 Like

Just figured that out, thanks.

1 Like

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