Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with Bool values and nil errors?

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

✓ Accepted answer

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.

2 comments

0

This helped, thankyou.

0

You're welcome.

This discussion is preserved as it was. New answers, comments, and votes are closed.