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

Help with Bool values and nil errors?

Asked by 9 years ago

My problem is, the doors do not switch between visible and Cancolide when the bool value is active. The error says OpenParts is a nil value

I have two doors, they are seperate grouped objects.

There is a closed door and an open door. This script is in the open door.

If the bool value is active then this happens The door is visible and can be collided with.

Parts.Transparency = 0 MainPart.CanCollide = true

The closed door is not CanCollide and is invisible but if the bool value is not true then the open door is invisible

Interact = script.Parent.Parent.Door.Interact
MainPart = script.Parent.MainPart


function GetOpenParts()                                             ------Open Door
    for i, v in pairs(script:GetChildren()) do
        if v:IsA("Part")or ("WedgePart") then return v end
    end
    return nil
end

function GetClosedParts()                                           ------Closed Door
    for i, v in pairs(script.Parent.Parent.Door:GetChildren()) do
        if v:IsA("Part")or ("WedgePart") then return v end
    end
    return nil
end

ClosedParts = GetClosedParts()
OpenParts = GetOpenParts()

if game.Workspace.GameSetup.Home.Values.DoorOpen == true 
    then 
    OpenParts.Transparency = 0
    MainPart.CanCollide = true
    ClosedParts.Transparency = 1
    Interact.CanCollide = false
else
    ClosedParts.Transparency = 0
    Interact.CanCollide = true
    OpenParts.Transparency = 1
    MainPart.CanCollide = false
end

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Small mistake (Line 6):

    for i, v in pairs(script:GetChildren()) do

should probably be

    for i, v in pairs(script.Parent:GetChildren()) do

unless the door's parts are in the script.

0
This helped, thankyou. IntellectualBeing 430 — 9y
0
You're welcome. Redbullusa 1580 — 9y
Ad

Answer this question