Hi i'm new to scripting so i'm sorry if i make stupid mistakes. Anyways i had made a door that turns its transparency to 1, and it's cancollide to false if you step on a certain part, and if you step on another certain brick it will turn the doors transparency to 0, and it's cancollide to false. I learned a little more about if and then but the guy didn't really explain it very well :/ i'm trying to make it so if the door's transparency is already 1 and you walk on the part that turns its transparency to 1, then it will instead turn it's transparency to 0. I also want to do this with the cancollide. Here's the normal working script that make's the door open if you walk over the correct part, same for closing.
Door = game.Workspace.Door -- Varible Enter = game.Workspace.Enter -- Varible Exit = game.Workspace.Exit -- Varible Enter.touched:connect(function()-- If Enter is touched, do the following Door.Transparency = 1 -- Sets the part Door 's transparency to 1 Door.CanCollide = false -- Sets the part Door 's cancollide to false end) Exit.touched:connect(function()-- If Exit is touched, do the following Door.Transparency = 0 -- Sets the part Door 's transparency to 0 Door.CanCollide = true -- Sets the part Door 's cancollide to false end)
Here's what i thought would work.
Door = game.Workspace.Door -- Varible Enter = game.Workspace.Enter -- Varible Exit = game.Workspace.Exit -- Varible Enter.touched:connect(function()-- If Enter is touched, do the following Door.Transparency = 1 -- Sets the part Door 's transparency to 1 Door.CanCollide = false -- Sets the part Door 's cancollide to false if Door.Transparency < 1 then Door.Transparency = 0 if Door.CanCollide < false then Door.CanCollide = true end end end) Exit.touched:connect(function()-- If Exit is touched, do the following Door.Transparency = 0 -- Sets the part Door 's transparency to 0 Door.CanCollide = true -- Sets the part Door 's cancollide to false end)
I thought that if the script would check if Door 's transparency was already 1 (meaning the part Enter has already been touched, which would open the door.) it would change it back to 0. Could i get some help? Also again i aplogize of any stupid mistakes i make. Also does anyone know good lua scripting tutorials? Not the one's made by roblox, they just don't seem to explain enough. One last thing, would it be better to put the door on like a timer, so if someone stepped on the part Enter it would open the door then close after an X amount of seconds? If that would be better for a game maybe you could show me how to do that? Or link a video of someone showing how to do that? Thanks :)
why not just have it be toggle? such as code like this
local Open = false local Door = game.Workspace.Door -- Variable local Enter = game.Workspace.Enter -- Variable local Exit = game.Workspace.Exit -- Variable local Debounce = true function toggle() if Debounce then Debounce = false if Open then Open = false Door.Transparency = 0 -- Sets the part Door 's transparency to 0 Door.CanCollide = true -- Sets the part Door 's cancollide to true else Open = true Door.Transparency = 1 -- Sets the part Door 's transparency to 1 Door.CanCollide = false -- Sets the part Door 's cancollide to false end wait(.5) --Mess with this if it doesn't close/open right Debounce = true end end Enter.Touched:connect(toggle) Exit.Touched:connect(toggle)
I made it so that it toggles and that there is a debounce so it doesn't open and close like crazy