Why is this error happening? attempt to call a number value

Error:

Workspace.Bomb.Bomb.Explode:9: attempt to call a number value

Code:

local bomb = script.Parent
local bombModel = bomb.Parent
local outerRadius = bombModel.OuterRadius
local innerRadius = bombModel.InnerRadius
wait(10)
outerRadius.Transparency = 0.5
innerRadius.Transparency = 0.6

for i in 1, #outerRadius:GetTouchingParts() do
	if outerRadius:GetTouchingParts()[i].Parent:IsA("Model") then
		local itemModel = outerRadius:GetTouchingParts()[i]
		local possibleHuman = itemModel:FindFirstChildWhichIsA("Humanoid")
		
		if possibleHuman then
			possibleHuman:TakeDamage(30)
		end
	end
end
for i in 1, #innerRadius:GetTouchingParts() do
	if innerRadius:GetTouchingParts()[i].Parent:IsA("Model") then
		local itemModel = innerRadius:GetTouchingParts()[i]
		local possibleHuman = itemModel:FindFirstChildWhichIsA("Humanoid")

		if possibleHuman then
			possibleHuman:TakeDamage(30)
		end
	end
end

wait(0.2)
outerRadius.Transparency = 1
innerRadius.Transparency = 1

wait(2)

bombModel:Destroy()

You’re calling GetTouchingParts() on the #outerRadius.
To avoid the error, wrap outerRadius:GetTouchingParts() with parenthesis;
which will look like:

for i in 1, #(outerRadius:GetTouchingParts()) do
-- Your rest of code ...
1 Like

Sorry for the late reply, had no internet for a while

It’s still not working, gives me the same error.

Shouldn’t it be for i = 1, #outerRadius:GetTouchingParts() do? You wrote in instead of =

1 Like

i hate that habit of mine

Thanks for the catch. It’s really annoying when I do that, especially when it’s highlighted.

Anytime, I knew something looked odd when there was an in in a for loop, it gets to us sometimes. But I think in this case it would be better to use the in pairs loop

1 Like