COD Zombies barrier

So. I’m working on a COD Zombies game, and I’m trying to create the barrier system. (Basically, while the zombie is touching the hitbox, a board gets deleted every second)


Script
local part = script.Parent
local b1 = part.board1
local b2 = part.board2 -- Assigning varibles and stuff
local b3 = part.board3
local b4 = part.board4

while task.wait(1) do
	local touching = part:GetTouchingParts() -- find parts touching the hitbox
	if touching.Name == "Zombie" then
		if part.part.Value.Value == 0 then -- checks if no boards are existing
			print("no boards to break")
			checkforboardvalue()
			return 
		end
	elseif touching.Name ~= "Zombie" then
		part.Value.Value = part.Value.Value - 1 -- lower the valye and update boards visually
		checkforboardvalue() -- cause of error ---
		print("Value is now:".. part.Value.Value) -- not printing for some reason??
	end
end

function checkforboardvalue()
	if part.Value.Value == 0 then
		b1.Transparency = 1
		b2.Transparency = 1
		b3.Transparency = 1 -- update boards visibly
		b4.Transparency = 1
		part.CanCollide = false -- let zombie walk through
	elseif part.Value.Value == 1 then
		b1.Transparency = 0
		b2.Transparency = 1
		b3.Transparency = 1
		b4.Transparency = 1
		part.CanCollide = true
	elseif part.Value.Value == 2 then
		b1.Transparency = 0
		b2.Transparency = 0
		b3.Transparency = 1
		b4.Transparency = 1
		part.CanCollide = true
	elseif part.Value.Value == 3 then
		b1.Transparency = 0
		b2.Transparency = 0
		b3.Transparency = 0
		b4.Transparency = 1
		part.CanCollide = true
	elseif part.Value.Value == 4 then
		b1.Transparency = 0
		b2.Transparency = 0
		b3.Transparency = 0
		b4.Transparency = 0
		part.CanCollide = true
	end
end

The issue is that, in the log, It keeps saying that it’s calling a nil value however, the value is not nil, and is actually 4 (for the 4 barriers) anyone know what the issue is? (The line causing the error is in the script.)

Your script is not optimized, but the problem is that the

local touching = part:GetTouchingParts()

is a table, and not a thing that u can get a “Name” like you did doing

if touching.Name == "Zombie" then

To resolve this, u could simple do a for loop at the table, the loop will return each part touching the the specific object, then u can do whatever you want with it.

local touching = part:GetTouchingParts()

for i,part in ipairs(touching) do 
   -- then u do what you want here.
end

The described error is due to the ‘checkforboardvalue’ function is never declared before the loop starts. Lua/Luau is read from top to bottom.

Hm. I could’ve swore that functions could be defined anywhere in a script.

Never been that way with Lua/Luau : )
Are you perhaps used to another language? (Such as C++)