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

I have a script to make my door open, But it doesn't work! Can someone help?

So, I've got this script in the 'Door' Union in a model. In the same model we have 2 Unions named 'Button1' and 'Button2' These 2 Button Unions both have ClickDetector In them. Can someone please fix this script to make the door open. Thank you.


local KCA = script.Parent.Parent.SoundPart["KeyCard Accepted"]
local KCD = script.Parent.Parent.SoundPart["KeyCard Denied"]
local DO = script.Parent.Parent.SoundPart.DoorOpen
local DC = script.Parent.Parent.SoundPart.DoorClose

local door = script.Parent
local bool = true
local bool2 = true
function openDoor()
	KCA:Play()
	KCD:Stop()
	DO:Play()
	script.Parent.Parent["Light 1"].BrickColor=BrickColor.Green()
	script.Parent.Parent["Light 2"].BrickColor=BrickColor.Green()
	for i = 1,(door.Size.z / 0.30) do
		wait()
		door.CFrame = door.CFrame - (door.CFrame.lookVector * 0.30)
	endhttps://assetgame.roblox.com/asset/?id=182529039#assetTypeId=10Military Canvas Tent image
	wait(3)
	DC:Play()
	
	for i = 1,(door.Size.z / 0.30) do
		wait()
		door.CFrame = door.CFrame + (door.CFrame.lookVector * 0.30)
	end
	script.Parent.Parent["Light 1"].BrickColor=BrickColor.Red()
	script.Parent.Parent["Light 2"].BrickColor=BrickColor.Red()
end

script.Parent.workspace.Door["Button1"].ClickDetector.MouseClick:connect(function()
	if bool then
		bool = false
		openDoor()
		wait(1)
		bool = true
	end
end)

script.Parent.workspace.Door["Button2"].ClickDetector.MouseClick:connect(function()
	if bool then
		bool = false
		openDoor()
		wait(1)
		bool = true
	end
end)

3 comments

0

Is there anything in the output

0

Is there anything in the output

1

Yes, errors are important to fixing the script. Please show us some.

1 answer

script.Parent.workspace.Door

Ok, so you messed up there.

What you need to do is to change "script.Parent.workspace.Door" to "workspace.Door" or "script.Parent.Parent.Door" at lines 39 and 30.

This is because you cannot put a specific name as a Parent, or it will try to find "workspace" inside your script's parent.

script.Parent.Parent.Door["Button1"].ClickDetector.MouseClick:connect(function()
    if bool then
        bool = false
        openDoor()
        wait(1)
        bool = true
    end
end)


script.Parent.Parent.Door["Button2"].ClickDetector.MouseClick:connect(function()
    if bool then
        bool = false
        openDoor()
        wait(1)
        bool = true
    end
end)

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