So I have a hiding mechanism for closets with 2 separate animations ( one for entering and the other for exiting ). The problem I’m having is that whenever the animation finishes, the player proceeds to rotate weirdly to the next position. Here’s a video demonstration:
I’ve been trying to work on this problem for a day and a half, searching both the forums and YT but the closest thing that could solve my problem was using TweenService and changing the animations to run on the spot instead. However, although this slightly helps with my entering animation ( at the cost of making the animation look a lil wonky ), it breaks the exiting animation orientation entirely.
I’ve played around with the position bricks’ cframes, the humanoid autorotate, the player’s primarypart, etc. Yet I’m still having this problem.
Here’s a snippet of the script for the closet ( I have this inside a custom camera script so that I can bind it back after exiting ):
-- Animations + Variables (Closet)
local closet1 = workspace.Apartment.Bedroom.Mechanics.Hide.closet1
local closet1anim = workspace.Apartment.Bedroom.Mechanics.Hide.closet1.Animation
local closet1exit = workspace.Apartment.Bedroom.Mechanics.Hide.closet1.Exit
local open = ts:Create(closet1.door.PrimaryPart, TweenInfo.new(.8), {CFrame = CFrame.new(Vector3.new(-9.099, 6.05, 14.631))})
local close = ts:Create(closet1.door.PrimaryPart, TweenInfo.new(.7), {CFrame = CFrame.new(Vector3.new(-9.099, 6.05, 11.181))})
local hide = game:GetService("ReplicatedStorage"):WaitForChild("Events").anim
local db = false
local loadanim = human.Animator:LoadAnimation(closet1anim)
local exitanim = human.Animator:LoadAnimation(closet1exit)
local playing = false
-- Closet Funcs
function hide1(hidepos, newpos)
human.AutoRotate = false
char.PrimaryPart.Anchored = true
char:PivotTo(hidepos * CFrame.Angles(0, math.rad(90), 0))
task.wait(.1)
loadanim:Play()
open:Play()
open.Completed:Wait()
close:Play()
loadanim.Stopped:Wait()
char:PivotTo(newpos * CFrame.Angles(0, math.rad(-90), 0))
task.wait(.1)
hide:FireServer()
end
function exit1(hidepos, newpos)
human.AutoRotate = false
char:PivotTo(newpos)
task.wait(.1)
exitanim:Play(.5)
open:Play()
open.Completed:Wait()
close:Play()
exitanim.Stopped:Wait()
char:PivotTo(CFrame.new(-7.324, 1, 9.417) * CFrame.Angles(0, math.rad(90), 0))
task.wait(.1)
char.PrimaryPart.Anchored = false
hide:FireServer()
end
hide.OnClientEvent:Connect(function(hidepos, newpos)
if hiding.Value == false and not db then
TargetAngleY = -90
runService:UnbindFromRenderStep("camupdate")
cam.CameraType = Enum.CameraType.Scriptable
human.WalkSpeed = 0
for _, v in pairs(char:GetChildren())do
if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
v.LocalTransparencyModifier = 0
v.CanCollide = false
end
if v.Name == "HumanoidRootPart" then
v.CanCollide = false
end
if v:IsA'Accessory' then
v:FindFirstChild('Handle').LocalTransparencyModifier = 0
v:FindFirstChild('Handle').CanCollide = false
end
if v:IsA'Hat' then
v:FindFirstChild('Handle').LocalTransparencyModifier = 0
v:FindFirstChild('Handle').CanCollide = false
end
end
cam.CFrame = workspace.Cameras.bedcam.CFrame
hide1(hidepos, newpos)
task.wait(.6)
updatechar()
runService:BindToRenderStep("camupdate", 2, update)
human.AutoRotate = true
db = true
else
game:GetService("UserInputService").InputBegan:Connect(function(input)
if db then
if input.KeyCode == Enum.KeyCode.F then
db = false
for _, v in pairs(char:GetChildren())do
if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
v.LocalTransparencyModifier = 0
v.CanCollide = false
end
if v.Name == "HumanoidRootPart" then
v.CanCollide = false
end
if v:IsA'Accessory' then
v:FindFirstChild('Handle').LocalTransparencyModifier = 0
v:FindFirstChild('Handle').CanCollide = false
end
if v:IsA'Hat' then
v:FindFirstChild('Handle').LocalTransparencyModifier = 0
v:FindFirstChild('Handle').CanCollide = false
end
end
TargetAngleY = 90
runService:UnbindFromRenderStep("camupdate")
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = workspace.Cameras.bedcam.CFrame
exit1(hidepos, newpos)
task.wait(.6)
updatechar()
runService:BindToRenderStep("camupdate", 2, update)
human.AutoRotate = true
human.WalkSpeed = 7
end
end
end)
end
end)
The main code is within a localscript, it communicates with a server script that enables the hiding value and proximity prompt. ( There are some other important stuff that occurs within the server script but that’s irrelevant to my current problem as they don’t affect the closet in any major way whatsoever )
Much appreciated to whoever can help me fix this problem!