Attempt to perform arithmetic (sub) on nil and number

i was learning doors tutorial part 7 by GnomeCode, on chapter 3 “Spawning monster”, and i’m scripting to spawn a monster and i got an error. it says “attempt to perform arithmetic (sub) on nil and number”, i clicked an error and it bring me here “local prevNum = number - 1”. somebody does have a clue to fix the issue?

1 Like

It means that number is nil, I think you might’ve forgotten to write some code he did. May you show us the code that you currently have in the script?

here’s a function module script

function shocker.New(number, generatedRooms)
	local enemyModel = game.ServerStorage.Enemies.Shocker:Clone()
	local prevNum = number - 1
	local maxNum = number + 1
	local prevRoom = generatedRooms[prevNum]
	if not generatedRooms[maxNum] then
		maxNum = #generatedRooms
	local maxRoom = generatedRooms[maxNum]
	enemyModel.Parent = game.Workspace
	shocker.Navigate(enemyModel, prevNum, maxNum, generatedRooms)
1 Like

Could it be that you forgot to pass in a number when creating a new monster? Where do you use shocker.New?

i think i figured out that having a issues of Door module script. playerenter:Fire() it seems it is missing a number so i white it playerenter:Fire() to playerenter:Fire(number), and that’s it!


See? i told you it fixes! i solved it by myself!

1 Like

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