Hello!
I’m trying to create a door with animations (something I haven’t done before) and it just isn’t working as intended. I’ve tried looking up what’s wrong and can’t figure it out. I think it has to do with the freezing animations and such.
https://gyazo.com/7b71fcb9d065632912f7b7617de9bf4c
local function doDoorOpen()
if DoorMoving == false then
DoorMoving = true
closeAnim:Stop()
openAnim:AdjustSpeed(1)
openAnim:Play()
openAnim:GetMarkerReachedSignal("End"):Connect(function()
openAnim:AdjustSpeed(0)
end)
DoorOpen = true
wait(0.85)
DoorMoving = false
end
end
local function doDoorClose()
if DoorMoving == false then
DoorMoving = true
openAnim:Stop()
closeAnim:AdjustSpeed(1)
closeAnim:Play()
DoorOpen = false
wait(0.85)
DoorMoving = false
end
end
ProximityPrompt.Triggered:Connect(function()
if DoorOpen then
doDoorClose()
else
doDoorOpen()
end
end)
Thanks for any help!
1 Like
You could just listen for the Tween to be completed using a Wait()
?
local function doDoorOpen()
if DoorMoving == false then
DoorMoving = true
closeAnim:Stop()
openAnim:AdjustSpeed(1)
openAnim:Play()
openAnim:GetMarkerReachedSignal("End"):Connect(function()
openAnim:AdjustSpeed(0)
end)
DoorOpen = true
openAnim.Completed:Wait()
DoorMoving = false
end
end
local function doDoorClose()
if DoorMoving == false then
DoorMoving = true
openAnim:Stop()
closeAnim:AdjustSpeed(1)
closeAnim:Play()
DoorOpen = false
closeAnim.Completed:Wait()
DoorMoving = false
end
end
ProximityPrompt.Triggered:Connect(function()
if DoorOpen then
doDoorClose()
else
doDoorOpen()
end
end)
This is an animation as stated in the title. I don’t know how to tween service with hinges and stuff.
try this
local function doDoorOpen()
if DoorMoving == false then
DoorMoving = true
closeAnim:Stop()
openAnim:AdjustSpeed(1)
openAnim:Play()
openAnim:GetMarkerReachedSignal("End"):Connect(function()
openAnim:AdjustSpeed(0)
end)
DoorOpen = true
wait(0.85)
DoorMoving = false
end
end
local function doDoorClose()
if DoorMoving == false then
DoorMoving = true
openAnim:Stop()
closeAnim:AdjustSpeed(1)
closeAnim:Play()
DoorOpen = false
wait(0.85)
DoorMoving = false
end
end
ProximityPrompt.Triggered:Connect(function()
if DoorOpen then
wait(1.5)
doDoorClose()
else
doDoorOpen()
end
end)
All i did is i added in a wait because
as you see here when the door opens, it closes right away
Same result, the closing is just delayed.
Whoopsie daisy then
Well if it’s an animation, you could still listen for the Stopped
event that’s provided by the AnimationTrack
object?
local function doDoorOpen()
if DoorMoving == false then
DoorMoving = true
closeAnim:Stop()
openAnim:AdjustSpeed(1)
openAnim:Play()
openAnim:GetMarkerReachedSignal("End"):Connect(function()
openAnim:AdjustSpeed(0)
end)
DoorOpen = true
openAnim.Stopped:Wait()
DoorMoving = false
end
end
local function doDoorClose()
if DoorMoving == false then
DoorMoving = true
openAnim:Stop()
closeAnim:AdjustSpeed(1)
closeAnim:Play()
DoorOpen = false
closeAnim.Stopped:Wait()
DoorMoving = false
end
end
ProximityPrompt.Triggered:Connect(function()
if DoorOpen then
doDoorClose()
else
doDoorOpen()
end
end)
Let me make this clearer. I don’t believe this is an issue with the timing, this has to do with the animation scripting.
While using .Stopped:Wait()
is a great idea for the variable, it’s not changing the way the doors are moving.
1 Like
well, did you at least try it?
Yes, that is why I said it has to do with the animation tracks.
1 Like
I believe the thing here is though, is that if you already have Animation
objects already made, it’ll be more difficult to replicate the changes made upon activating the Prompt since you’re literally manipulating how the Positioning & Time is dealt with
Personally what I’d do, is use TweenService
, create 2 variables that give you your Open/Close
Positionings, and when the Prompt gets triggered, save the current position of where the door is at, & tween it depending if the door is “Opened” or “Closed” so that way it’s easier to handle it
Thing is, will that tween on the hinge? I’m not exactly sure how it even works to be honest (the door hinge stuff, not tween service).
You could make it a Model and set its PrimaryPart
property to the hinge perhaps, that way you can tween it so it doesn’t look weird?
(Idk how Building works so I’m just guessing)
I made the door model, and I can confirm that there are no hinge parts, only the frame and the door itself.
1 Like
After looking into it, the door just it’s joints set to where the hinge would be which is why you can animate it like that. I have no clue how you’d tween that.
local function doDoorOpen()
if DoorMoving == false then
DoorMoving = true
wait(0.4) -- small bit of delay
openAnim:Play()
openAnim:GetMarkerReachedSignal("End"):Connect(function()
openAnim:Stop()
end)
DoorOpen = true
wait(0.85)
DoorMoving = false
end
end
local function doDoorClose()
if DoorMoving == false then
DoorMoving = true
wait(0.4) -- small bit of delay, again
closeAnim:Play()
closeAnim:GetMarkerReachedSignal("End"):Connect(function()
closeAnim:Stop()
end)
DoorOpen = false
wait(0.85)
DoorMoving = false
end
end
ProximityPrompt.Triggered:Connect(function()
if DoorOpen then
spawn(doDoorClose)
else
spawn(doDoorOpen)
end
end)
THIS SHOULD FIX IT
NOTE : IN THE FUTURE WHEN CHANGING THE SPEED OF AN ANIMATION THAT ISN’T PLAYING, THAT WON’T DO ANYTHING, WHEN AN ANIMATION IS PLAYED IT RESETS ITSELF TO DEFAULT SPEED THEREFORE YOU SHOULD ADJUST THE SPEED AFTER THE ANIMATION STARTS PLAYING
If this doesn’t work, it’s mostly because of how the animations you made work with eachother, I suggest learning TweenService.