Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is pin down detector for bowling lane not working. How to fix?

Asked by 3 years ago
Edited by JesseSong 3 years ago

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

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" imKirda 4491 — 3y
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 JesseSong 3916 — 3y

Answer this question