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

Why doesn't my door script work?

I'm using a click detector, so when a player touches a door, the door will have 1 transparency and wont be cancollide? my script is:

script.Parent.MouseButton1Click:connect(function(click) -- If the door is click do:
script.Parent.Parent.Transparency = 1 -- Sets Transparency to 1 so its invisible
script.Parent.Parent.CanCollide = false -- Sets CanCollide to false so its gothrough
wait(5) -- Door will open for 5 seconds
script.Parent.Parent.CanCollide = true -- Set CanCollide back to true
script.Parent.Parent.Transparency = 0 -- Change the transparency back to 0
if script.Parent.Parent.CanCollide == false then -- If CanCollide is false then
script.Parent.Parent.CanCollide = true -- Set CanCollide to true if its at false
else -- If CanCollide was true already
print("CanCollide part works") -- This is what "game" says if the CanCollide part of the script works.
wait(0.1) -- Wait 0.1 seconds
if script.Parent.Parent.Transparency == 1 then -- If its at 1 then
script.Parent.Parent.Transparency = 0 -- Set it to 0 if its at 1
else -- If the transparency was 0 already
print("Both parts work, Script works") -- This is what "game" says after it checks the Transparency
end -- Ends the first "if"
end -- Ends the seconds "if"
end) -- Ends the whole script

NOTE: If you know, please just dont ignore this, give all what you've got.

Simplier version:

script.Parent.MouseButton1Click:connect(function(click) -- If the door is click do:
script.Parent.Parent.Transparency = 1 -- Sets Transparency to 1 so its invisible
script.Parent.Parent.CanCollide = false -- Sets CanCollide to false so its gothrough
wait(5) -- Door will open for 5 seconds
script.Parent.Parent.CanCollide = true -- Set CanCollide back to true
script.Parent.Parent.Transparency = 0 -- Change the transparency back to 0
end

4 answers

✓ Accepted answer

Once again, your error was very very small. "MouseButton1Click" is not a proper event for a ClickDetector. Instead, you use "MouseClick" for ClickDetectors.

I've shortened the script for you also.

debounce = false

script.Parent.MouseClick:connect(function(click)
if debounce == false then
debounce = true
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = false
wait(5)
script.Parent.Parent.CanCollide = true
script.Parent.Parent.Transparency = 0
debounce = false
elseif debounce == true then
script.Parent.Parent.CanCollide = true
script.Parent.Parent.Transparency = 0
debounce = false
end
end)

2 comments

0

Thanks! Oh well, I learn from my mistakes right?

0

Yep.

I think you need to inset a ClickDetector into the door, if you haven't already :)

3 comments

0

insert

0

apologies, didn't read first bit, you already have a clickdetector

0

Its k, people always make mistakes on big scripts.

What are you trying to do? Make the door transparent and cancollide if the brick is clicked??

3 comments

0

"script.Parent.Parent.Transparency = 1" --Wait, wait, do you have 1 too many Parents?

0

No, the script is in the click detector, so to get to the door, i will need 2 parents.

0

And yes, make the door transprent and be cancollide

Your script is way more coded then it needs to be

function Click()
script.Parent.Parent.Door.CanCollide = false
script.Parent.Parent.Door.Transparency = 1
wait(5)
script.Parent.Parent.Door.CanCollide = true
script.Parent.Parent.Door.Transparency = 0
end
script.Parent.MouseButton1Click:connect(Click)

2 comments

0

Yes ik, but, the ifs will recheck the door's properties.

0

And the script doesn't work

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