I am trying to make a detector that checks whether a bowling pin is down or not after the player throws their 1st ball. I keep getting the same error every time. This is my code.

local function IsPinDown(pinNumber)
	local pin = pins:FindFirstChild("Pin"..pinNumber)
	local rotX,rotZ = math.abs(pin.Rotation.X),math.abs(pin.Rotation.Z)
	if rotX > 30 or rotZ > 30 then
		return "IsDown"
	else
		return "NotDown"
	end
end

My error is:

 Workspace.Model.Model.A2 Machine.Lane2.Touchpart.Script:41: attempt to index nil with 'Rotation'

Please help if possible.

####Reformed by JesseSong

2 comments

1

"FindFirstChild" might return nil if the pin is not found in "pins", you need to check if it exists before indexing it with "Rotation"

0

bittyboy1234 when making incorporating code in questions/answers please use code blocks properly. I even edited some grammatical errors. See help: https://scriptinghelpers.org/help/how-post-good-questions-answers