Sorry this post is a bit long, but it could potentially be useful for everyone if we can find a solution.
Hello, I’m trying to create a Door System with a Rig + Animation Controller to animate the door. But I’m having trouble creating a proper script.
I’d like it to stay open as long as the player is near the door, and close it once he’s gone.
I thought of creating a transparent part, detecting when a player Touch the part to animate the door to open it, then detect when the Touch Ended to animate the door to close it.
But when the door is open, I can only think of two ways to keep it open (as you know, when an animation stops, the object returns to its initial position):
1/ Put a second transparent door that I make visible when the opening animation is finished, when the Touch Ended, I animate this second door to close it, then I make it transparent, and I make the first door visible again.
2/ Create a door opening animation that stays open for a very long time (2 minutes…), and when the Touch Ended, I animate the door close with a Priority.Action2 to override the first animation, when the door is closed, I stop both animations.
Maybe there could be better solution that i didn’t know or didn’t think about …
Here is a first script i’ve made to see what happens. If you have some tips or Advice, i take it ! Thanks for reading !
local AnimOpenValue1 = script.OpenDoor1
local AnimCloseValue1 = script.CloseDoor1
for i,v in workspace.Doors:GetChildren() do
local AnimOpen1 = v.AnimationController.Animator:LoadAnimation(AnimOpenValue1)
local AnimClose1 = v.AnimationController.Animator:LoadAnimation(AnimCloseValue1)
AnimOpen1.Priority = Enum.AnimationPriority.Action
AnimClose1.Priority = Enum.AnimationPriority.Action
local db = false
v.TouchDetectDoor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if db == false then
db = true
AnimOpen1:Play()
end
end
end)
v.TouchDetectDoor.TouchEnded:Connect(function()
AnimClose1:Play()
task.wait(AnimClose1.Length)
db = false
end)
end