Keep getting "attempt to index number with 'Value'"

  1. What do you want to achieve?
    I am trying to make the amount of pellets be subtracted by 250 every .25 seconds

  2. What is the issue?
    The loop stops whenever the amount of pellets is below the upgradeMod:GetAmountOfPelletsPerDrop() (returns 250)
    and outputs an error:
    image

  3. What solutions have you tried so far?
    I did my best to see what the problem was but I don’t have a clue

The part of the script where I believe the issue is

--[[line forty five]] pelletAmount.Changed:Connect(function() -- "pelletAmount" is a NumberValue
	local amount = pelletAmount.Value
	while pelletAmount.Value > 0 do
		print('fefe')
		if pelletAmount.Value >= upgradeMod:GetAmountOfPelletsPerDrop() --[["upgradeMod:GetAmountOfPelletsPerDrop()" returns 250]] then
			print('fer')
			pelletAmount.Value -= upgradeMod:GetAmountOfPelletsPerDrop()
			script.Parent.Pellets.Size = Vector3.new(pellet.Size.X, perPellet * pelletAmount.Value, pellet.Size.Z) -- the size of this object represents the quantity of pellets
		else
			pelletAmount = 0
			-- more will be added later
		end
		wait(.25)
	end
end)

Try this:

	local amount = pelletAmount.Value
	while pelletAmount.Value > 0 do
		print('fefe')
		if pelletAmount.Value >= upgradeMod:GetAmountOfPelletsPerDrop() --[["upgradeMod:GetAmountOfPelletsPerDrop()" returns 250]] then
			print('fer')
			pelletAmount.Value -= upgradeMod:GetAmountOfPelletsPerDrop()
			script.Parent.Pellets.Size = Vector3.new(pellet.Size.X, perPellet * pelletAmount.Value, pellet.Size.Z) -- the size of this object represents the quantity of pellets
		else
			pelletAmount.Value = 0
			-- more will be added later
		end
		wait(.25)
	end
end)

Doesn’t work. The while loop doesn’t start for some reason

Maybe just decrement the pellet amount in your if statement body and get rid of the else clause? Not really sure what you’re trying to do here

I’m not sure how’d I do that without it going into the negatives

image
you are getting value of a value?
or a NumberValue is named as Value?

1 Like

Yeah that local amount = pelletAmount.Value was from something else I tried, just ignore it. And no, it is not named as Value

I see, can you put
paint(typeof(pelletAmount)) before while loop?

pelletAmount = 0

Did you mean to type

pelletAmount.Value = 0
1 Like

I put it before the loop but it just gave another error. What I put was:

pelletAmount.Changed:Connect(function() -- "pelletAmount" is a NumberValue
	pellet(typeof(pelletAmount))
	while pelletAmount.Value > 0 do
		print('fefe')
		if pelletAmount.Value >= upgradeMod:GetAmountOfPelletsPerDrop() --[["upgradeMod:GetAmountOfPelletsPerDrop()" returns 250]] then
			print('fer')
			pelletAmount.Value -= upgradeMod:GetAmountOfPelletsPerDrop()
			script.Parent.Pellets.Size = Vector3.new(pellet.Size.X, perPellet * pelletAmount.Value, pellet.Size.Z) -- the size of this object represents the quantity of pellets
		else
			pelletAmount = 0
			-- more will be added later
		end
		wait(.25)
	end
end)

The error was:
image

image
This basically changing your instance with 0
so maybe you meant pelletAmount.Value = 0?

typeof can be used on instances, but your pelletAmount variable is set to 0

1 Like

Yes I did mean to type that, thank you. But after fixing that I came across this which I don’t understand:
image

Just disconnect then connect it again.

local connection
function dothing()
   connection:Disconnect() 
   connection = pelletAmount.Changed:Connect(dothing)
	while pelletAmount.Value > 0 do
		print('fefe')
		if pelletAmount.Value >= upgradeMod:GetAmountOfPelletsPerDrop() --[["upgradeMod:GetAmountOfPelletsPerDrop()" returns 250]] then
			print('fer')
			pelletAmount.Value -= upgradeMod:GetAmountOfPelletsPerDrop()
			script.Parent.Pellets.Size = Vector3.new(pellet.Size.X, perPellet * pelletAmount.Value, pellet.Size.Z) -- the size of this object represents the quantity of pellets
		else
			pelletAmount.Value = 0
			-- more will be added later
		end
		wait(.25)
	end
end
end
connection = pelletAmount.Changed:Connect(dothing)
1 Like

I believe Re-Entrancy Depth refers to the Connection being fired too often, since you are changing PelletAmount.Value within the .Changed connection.

You could try adding a Debounce, or refactor your code out of a .Changed connection.

1 Like