Attempt to index number with 'Value'

--This script is a enormously shortened script. 
--Any of the variables that aren't defined in here are already defined. 
--That's why I pointed that out.
local EnemyNumber = workspace.Enemies:WaitForChild("EnemyNumber")

function gamerun()

		local TI = BossesFolder.HIM:Clone()
		TI.Parent = workspace.Enemies
		Enemies.Value += 1
		EnemyNumber.Value += 1
		
		local SAUR = BossesFolder.SAUR:Clone()
		SAUR.Parent = workspace.Enemies
		Enemies.Value += 1
		EnemyNumber.Value += 1

end

gamerun() -- starts the function

For context, this is a function that starts the game the moment it is Enabled. After the player beats the first boss called “TI”, a 2nd boss called “SAUR” spawns after a while. However since I’m showing a heavily shortened script, you will have to assume I already have put in everything, since this post is focusing on the main problem that breaks the entire script and the game for the players, which is EnemyNumber attempting to increase the 2nd time.

Let’s get straight to the problem, the problem is EnemyNumber.Value. When I attempt to increase the EnemyNumber value the 2nd time (below the SAUR variable), the script returns a error, saying attempt to index number with 'Value'. I know I wrote mostly all the code and it works but when the function fires off trying to increase the EnemyNumber.Value the 2nd time, the script returns a error, yet it is written the same way that works for the first time. I do not know why this is the case and I have absolutely 0 idea how to fix the error it gives. If anyone would like to help, please do!

If anyone is thinking that this post is just a way to cultivate laziness, it’s not. I have yet been able to fix this issue. Trying to increase a value once and then after a while doing it again in the same function breaks the script, which I haven’t been able to figure out a fix for this issue.

Either you’re reading the wrong line for the error or you’ve redefined EnemyNumber somewhere. Apart from that, nobody can help you

1 Like

Is there anywhere else in the code you are declaring EnemyNumber?

I.e. anything that says

EnemyNumber = 0 --could be anything
1 Like

I found it, I found one line of code that says “EnemyNumber = 0” or anything which could be the source of the problems. Can’t believe I didn’t try and find if there was one of those where I forgot to put “EnemyNumber.Value”. Although I do have to say thank you, since I made a pretty bad mistake not checking if that was the case.

1 Like

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