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

Why doesn't my door script work?

Asked by 10 years ago

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

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
10 years ago

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)
0
Thanks! Oh well, I learn from my mistakes right? Operation_Meme 890 — 10y
0
Yep. Discern 1007 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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

0
insert Shaydesilva 85 — 10y
0
apologies, didn't read first bit, you already have a clickdetector Shaydesilva 85 — 10y
0
Its k, people always make mistakes on big scripts. Operation_Meme 890 — 10y
Log in to vote
-1
Answered by
c0des 207 Moderation Voter
10 years ago

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

0
"script.Parent.Parent.Transparency = 1" --Wait, wait, do you have 1 too many Parents? c0des 207 — 10y
0
No, the script is in the click detector, so to get to the door, i will need 2 parents. Operation_Meme 890 — 10y
0
And yes, make the door transprent and be cancollide Operation_Meme 890 — 10y
Log in to vote
-1
Answered by
Prioxis 673 Moderation Voter
10 years ago

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)
0
Yes ik, but, the ifs will recheck the door's properties. Operation_Meme 890 — 10y
0
And the script doesn't work Operation_Meme 890 — 10y

Answer this question