So I know basic scripting. The thing is, I have 2 scripts. One of the opens and doesn't close, and the other doesn't move. How would I edit the following so that it closes after 2 seconds? Failing this, can you suggest a new script that works in this manner.
local Part = script.Parent local newPos = Part.Position + Vector3.new(7,0,0) local Time = 5 local Increment = 0.1 local Debounce = false local Diff = newPos - Part.Position local Mag = Diff.magnitude local Direction = CFrame.new(Part.Position, newPos).lookVector function MovePart() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Part.CFrame = Part.CFrame + (Direction * Increment) wait( (Time/Mag) * Increment ) end Debounce = false end script.Parent.Touched:connect(MovePart)
Currently, when you first touch it, it moves to where I want it to. I don't know how to make it go back using the same form of algorithm
Thanks FaultyMatrix
This script is extra useful because the door will open in the direction it is facing. That means you don't have to configure the Vector3's every time you make a new door. You simply have to rotate it the right way:
local p = script.Parent local d = false p.Touched:connect(function() if d then return end d = true for i=1, 100 do -- 100 = Distance p.CFrame = p.CFrame + p.CFrame.lookVector * .1 -- .1 = Speed wait() end wait(1) for i=1, 100 do -- 100 = Distance p.CFrame = p.CFrame + p.CFrame.lookVector * -.1 -- Negative here to go back wait() end d = false end)