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

Roblox Studio-Click A Button To Open A Door Not Working! How do I fix this?

Please explain to me what's wrong with my script, keep in mind I only started scripting 1 week ago! I've placed the script as a child to the click detector, The click detector is a child of the actual door. Also, the "wait(3)" is so that you have to click the door , have it open, then close automatically. Need any more info on what I've done in my game that might have caused this? Discord me at:

ThatOneAviator#0311

function DoorOpen()

game.Workspace.OpeningDoor.Transparency = Transparency.new(0.6)

game.Workspace.OpeningDoor.CanCollide = CanCollide.new("false")

wait(3)

game.Workspace.OpeningDoor.Transparency =Transparency.new(0)

game.Workspace.OpeningDoor.CanCollide = CanCollide.new("true")

end

  

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

2 comments

0

Cancollide isn't a class with a constructor

0

it is a boolean

3 answers

✓ Accepted answer

I'm not quite sure what you are trying to do by repeating the same thing after the wait(3) but the main issue i see are the

Transparency.new(0.6)
CanCollide.new("false")

there is no such thing as "Transparency.new()" or "CanCollide.new()".

Also you already picked script's parent which is the clickdetector, therefore you don't need script.Parent.ClickDetector instead it should be only script.Parent

which means your code should look something like that:

script.Parent.MouseClick:Connect(function()
	script.Parent.Parent.Transparency = 0.6
	script.Parent.Parent.CanCollide = false
	wait(3) --- i will asume that after 3 second you wanted to change the door back to normal
	script.Parent.Parent.Transparency = 0
	script.Parent.Parent.CanCollide = true
end)

2 comments

0

By wait, i wanted to have the door open with one click, have the player walk through within 3 seconds and then have the door close on it's own!

0

Im so blind, i didn't see what your assumption was in the script, sorry for spamming you!

Transparency and CanCollide properties don't have constructor functions, so instead of

CanCollide.new("False")
Transparency.new(0.6)

just write

"False"
0.6

You're also trying to set the Transparency and CanCollide properties to the same value, so when you click the door nothing would appear to happen. You should do something like:

local door = script.Parent.Parent
local ClickDetector = script.Parent
local function openDoor()
    door.Transparency = 0.6
    door.CanCollide = false
    wait(3)
    door.Transparency = 0
    door.CanCollide = true
end
ClickDetector.MouseClick:Connect(openDoor)

Hope this helps!

Hi. I've noticed that on line 17 you put script.Parent.ClickDetector, while you said that the script is a child of the ClickDetector. Also, the Transparency and CanCollide values do not need .new() it should be:

function DoorOpen()
game.Workspace.OpeningDoor.Transparency = 0.6
game.Workspace.OpeningDoor.CanCollide = "false"
wait(3)
game.Workspace.OpeningDoor.Transparency = 0.6
game.Workspace.OpeningDoor.CanCollide = "false"
end
script.Parent.MouseClick:connect(DoorOpen)

Please test the script and correct my answer if it works!

2 comments

0

It worked! The only problem is that CanCollide wont turn to false! I tried everything, from my way of setting properties, to new ways on the internet (not very many).

0

oh

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