Attempt to compare nil and number when 'nil' should clearly exist

Hello!

I am not sure why I am getting this issue, however I am. When I touch this part, it prints ‘HumanoidRootPart’ as it should, however when I try to check the Size value of the hole, it returns nil when it should clearly return 6, which is my hole’s size.

Hierarchy:
Screen Shot 2020-09-26 at 5.47.23 PM Screen Shot 2020-09-26 at 5.47.36 PM

wait()

for i,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA('BasePart') then
		local DeterminedValue
		local Consumeable = v:FindFirstChild('Consumeable')
		if Consumeable then
			if Consumeable.Value == true then
				local Size = Instance.new('NumberValue', Consumeable.Parent)
				local V3 = v.Parent:GetExtentsSize()
				local X = V3.X
				local Y = V3.Y
				local Z = V3.Z
				if Y > Z or Y == Z then
					print('Y')
					DeterminedValue = Y
				elseif Y < Z then
					DeterminedValue = Z
					print('Z')
				end
			end
		end
		v.Touched:Connect(function(toucher)
			if toucher.Parent:FindFirstChild('Humanoid') then
				if toucher.Parent:FindFirstChild('Size').Value >= DeterminedValue then
					print('Consumeable by '..tostring(toucher))
				else
					print('Not consumeable by '..tostring(toucher))
				end
			end
		end)
	end
end

Here’s the output:
Screen Shot 2020-09-26 at 5.48.31 PM

2 Likes

Print both variables before comparing them.

1 Like

This is the output: ‘Workspace.Bollard.Script:22: attempt to concatenate string with nil’

Here’s the line I added:

print('Size:' ..tostring(toucher.Parent.Size)..' Size Value: '..toucher.Parent.Size.Value..' DeterminedValue: '..DeterminedValue)
1 Like

Just print the raw values without touching them in any way.

2 Likes

Apparently DeterminedValue isn’t being assigned a value, one sec

Is DeterminedValue defined? You should check that :FindFirstChild(“Size”) isn’t nil. You should also not store this in the players character as exploiters can freely modify and delete stuff in the players character.

1 Like

Yeah, I checked that, it was DeterminedValue, however I am not sure why DeterminedValue isn’t being assigned anything, I added the full script in the original post.

Got it, I feel like an idiot because it was a tiny hierarchy issue.

should have been

local Consumeable = v.Parent:FindFirstChild('Consumeable')

You should set DeterminedValue to something by default, maybe math.huge?

1 Like

Yeah, good idea. I will do that. If I missed something, it would just be not consumable.

And please don’t store the size in the player character, exploiters can edit/delete it and then the script would break.

1 Like

Oh, no worries, all the checks and changes are server sided. If they were to exploit it, it would only be client-sided changes and only visible to themselves.

No, due to clients having network ownership of their characters any changes to things in the character get replicated unless the property is marked as non-replicated(for example humanoid health).

1 Like

Oh, really? I will make it out of the character then, probably a module. Thanks for letting me know!

You can store it in the players player instance, this way the size is also saved if the character gets removed.

1 Like

Oh, that’s right, never thought of that. That’s probably easier then, thanks!