Hello devs!
I wanted do script which playing animations in animation controller of hands in camera but i got problem.
When i start gun equipping animation again(player equipped tool) animation dont starts for 1 frame but then it starts.
Here all code:
local Events = script.Parent.Events
local CurConfig = nil
local CurToolInHands = nil
local CurToolInCharacter = nil
local CurHands = nil
local EquipConnection = nil
local ToolEquipped = false
-----------------------------Loading anims
for _,Config in pairs(game.ReplicatedStorage.Configurations:GetChildren()) do
if Config.ClassName == "Configuration" then
for _,Anim in pairs(Config.Data:GetChildren()) do
if Anim.ClassName == "Animation" then
require(Config.Data).Animations[Anim.Name] = Config:FindFirstChildOfClass("Model").AnimationController:LoadAnimation(Anim)
end
end
end
end
------------------------------Functions
-----------------------------Events
Events.EquipConfig.Event:Connect(function(Config,Tool)
if Config ~= CurConfig then
if EquipConnection then
EquipConnection:Disconnect()
EquipConnection = nil
end
if CurHands then
for Index,Anim in pairs(CurHands.AnimationController:GetPlayingAnimationTracks()) do
Anim:Stop(0)
end
CurHands.Parent = nil
end
CurConfig = Config
CurToolInCharacter = Tool
local Data = require(Config.Data)
CurHands = Data.FrameworkValues.Hands
CurHands.Parent = workspace.CurrentCamera
CurToolInHands = CurHands:FindFirstChildOfClass("Model")
if Data.Animations.EquippingAnim then
Data.Animations.EquippingAnim:Play(0)
EquipConnection = Data.Animations.EquippingAnim.Stopped:Connect(function()
EquipConnection:Disconnect()
EquipConnection = nil
ToolEquipped = true
if Data.Animations.HandlingAnim then
Data.Animations.HandlingAnim:Play(0)
end
end)
else
ToolEquipped = true
if Data.Animations.HandlingAnim then
Data.Animations.HandlingAnim:Play(0)
end
end
end
end)
-----------------------Hands render
game:GetService("RunService").RenderStepped:Connect(function(DT)
if CurHands then
CurHands:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame)
end
end)
And here a video:
(Pm tool dont have equipping anim so its just dont playing it)
So how you see sometimes when i equip ak it dont play anim for one frame but then doing it