Attempted to index 'nil' Error from intValue object that cannot carry a 'nil' value

for _, object in pairs(checkpoints:GetChildren()) do
	local num = object.Name
	local stage = tonumber(object.Name)
	local hitbox = object.HitBox
	local label = object.Number.SurfaceGui.TextLabel
	label.Text = "Stage " .. num
	
	hitbox.Touched:connect(function(hit)
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		
		if humanoid then
			local player = humanoid.Parent.Name
			local plr = game:GetService("Players"):FindFirstChild(player)
			print("Hit Player Name, " .. player)
			
			-- Find player's folder position.
			local success, folderName = getPlrFolder(player)
			
			local confirmation = false
			
			if success then
				local folder = sss:FindFirstChild(folderName)
				local a = tostring(folder.Stages.Value)
				print("text " .. a)
				local previousStage = folder.Stages.Value
				local difference = stage - previousStage
				
				if difference < 2 or previousStage == 0 then
					folder.Stages.Value = stage
					
					print(player .. " stage set to " .. tostring(folder.Stages.Value))
					
					confirmation = true -- Unlocked Stage Confirmed
				else
					plr:Kick(prefix .. "Skipped a Stage. Stage Confirmation failed.")
				end
			end
			
			if confirmation then
				print(prefix .. player .. " reached Stage " .. num)
			else
				print(prefix .. "Stage Confirmation for " .. player .. " at stage " .. num .. " failed.")
			end
		end
	end)
	
	--object.Touched:connect(function(hit)
end

Above is my code block ^^^^

Here is where the error is happening: local previousStage = folder.Stages.Value.
I even added a print statement before it, but its not printing at all…?

I really need help with this, thanks :slight_smile:

1 Like

There’s something in your conditional statement that’s setting the value of Stages to nil (which is causing an error because nil is not a numerical value)

if difference < 2 or previousStage == 0 then
   folder.Stages.Value = stage

Can you try adding print(stage) and see what it outputs?

1 Like
if success then
				print(stage)
				local folder = sss:FindFirstChild(folderName)
				local a = tostring(folder.Stages.Value)
				print("text " .. a)
				local previousStage = folder.Stages.Value
				local difference = stage - previousStage

I added a print(stage) there and it outputs ā€˜1’.
(Also its still not printing this print statement before the error, which is weird.)

1 Like

Attempted to index ā€˜nil’ means that it couldn’t find a object named stages or an object with the property(or a child) called Value this could be a couple things

local success, folderName = getPlrFolder(player)

Maybe this isn’t returning a foldername*
You don’t seem to have a Debounce so this might be whats wrong

if difference < 2 or previousStage == 0 then
	folder.Stages.Value = stage

You code will run for each part that touches it so basically if UpperArm touches it, it will run.
if LowerTorso Touches it, it will run etc etc

Edit: Attempt to index ā€˜nil’ should also come with what you tried to index it with so the error should say something like this
Attempt to index ā€˜nil’ with Value
or
Attempt to index ā€˜nil’ with ā€˜Stages’

2 Likes

The error returns ā€˜Attempted to index ā€˜nil’ with ā€˜Stages’’

1 Like

Then ā€œStagesā€ is not an Object in the folder try loading the game then checking the folder in explorer

1 Like

Ah thanks, I tried to check what path it was aiming for and it was trying to find the folder directly in SSS rather than inside its location of PlayerInformation.

local folder = sss:FindFirstChild(folderName)

this was the root of the error ^ Thanks for the help :smiley:

1 Like