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

How can I get my Open/Close Owner Only Door to work?

So I am trying to make a Open/Close Owner Only Door for my Robloxian Rebearth Tycoon and for others. I have got this close button so far but there is an error.

function onClicked()
        script.Parent.Parent.OwnerOnlyDoor, OwnerOnlyDoor2, OwnerOnlyDoor3, OwnerOnlyDoor4.BrickColor= Really red
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

There is a red line under end in the script on studio, and when I click the button it doesn't change the color either when I click it. I have multiple Owner Only Doors so its like bars also. Please help!

2 answers

✓ Accepted answer

You have to define each of the BrickColor separately.

function onClicked()
	local Model = script.Parent.Parent
	Model.OwnerOnlyDoor.BrickColor = BrickColor.new("Really red")
	Model.OwnerOnlyDoor2.BrickColor = BrickColor.new("Really red")
	Model.OwnerOnlyDoor3.BrickColor = BrickColor.new("Really red")
	Model.OwnerOnlyDoor4.BrickColor = BrickColor.new("Really red")
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

There's another way you can achieve the same effect.

-- By using a "for" loop
function onClicked()
	local Model = script.Parent.Parent
	for i, v in pairs (Model:GetChildren()) do
		v.BrickColor = BrickColor.new("Really red")
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
--[[ THIS WILL ONLY WORK IF EVERYTHING IN script.Parent.Parent IS NOTHING BUT:
OwnerOnlyDoor
OwnerOnlyDoor2
OwnerOnlyDoor3
OwnerOnlyDoor4]]

EDIT

Sorry, disregard the "3."

1 comment

0

This is not working...

function onClicked() script.Parent.Parent.OwnerOnlyDoor, OwnerOnlyDoor2, OwnerOnlyDoor3, OwnerOnlyDoor4.BrickColor= 'Really red' end

You forgot the ''

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