I made sliding glass doors using CFframe+Vector3 line, its activated using a .touched:connect(Function) but the problem im having is when touching the part the script isnt following thru, the door is just FLYING to the other side of the map.
function DoorTouch(hit) for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(.3,0,0) end wait(4) for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(-.3,0,0) end end game.Workspace.DoorSensor.Touched:connect(DoorTouch)
A touched function will fire numerous times in a second, thus running the code numerous times a second. To prevent this we use a debounce. A debounce is just a variable that we change to true when the code runs and require it to be false for it to run again. Adding one would make your script look like this:
orTouch(hit) if debounce == false then for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(.3,0,0) end wait(4) for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(-.3,0,0) end debounce = false end end game.Workspace.DoorSensor.Touched:connect(DoorTouch)
I apologize if this is messy as I am on a phone right now, if the output gives you any errors please leave a comment and I'll get back to you ASAP
-Cmgtotalyawesome
You should detect if it was touched by a humanoid if you want it so that it opens on player touch.
function DoorTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(.3,0,0) end wait(4) for I=1,20 do wait(.2) script.Parent.CFrame=script.Parent.CFrame+Vector3.new(-.3,0,0) end end end game.Workspace.DoorSensor.Touched:connect(DoorTouch)
sorry for formatting, on mobile.