Note! Im trying to make people able to reproduce this and test themself and maybe we can come to a conclusion on how to solve this case. Warning: There might be alot to read for those who like short questions.
I have noticed passing animationtrack client to server or opposite results in nil. So for a workaround on this I tried firing off the animation in the serverscript and hopefully get the animation by using "GetPlayingAnimationTracks"
1st attempt
-- Comments ---
--LocalScript in a textbutton in a gui. This is an invokeserver
-- The returnvalue should be the animationtrack
--------------------------------------------------------
mouse.Button1Down:Connect(function()
local Track = Action:InvokeServer()
print(Track )
end)
-- Comments --
-- ServerScript [placed in serverscriptservice]
-- Inside the ServerScript there is a folder named Animations
-- Inside this folder there are several animations objects
-- Our target animation will be the object named "Attack1"
--------------------------------------------------------
Action.OnServerInvoke = function(player)
local Attack1 = script.Animations:WaitForChild("Attack1")
local Track = char.Humanoid:LoadAnimation(Attack1)
print(Track )
Track:Play()
return Track
-- Output
-- client --> nil
-- Server --> Attack1
2nd attempt -- given that we have char which is the character and humanoid -- The code below will return an array of the AnimationTracks currently being played on the Humanoid.
for _,anim in pairs(char.Humanoid:GetPlayingAnimationTracks()) do
print(anim.Name)
end
With this we can do a workaround to get the animation instead of nil
-- Client
local player = game.Players.LocalPlayer
local char = player.Character
if not char or not char.Parent then
char = player.CharacterAdded:wait()
end
mouse.Button1Down:Connect(function()
local Track = Action:InvokeServer()
for _,anim in pairs(char.Humanoid:GetPlayingAnimationTracks()) do
print(anim.Name)
end
end)
-- Server
Action.OnServerInvoke = function(player)
local char = player.Character
local Attack1 = script.Animations:WaitForChild("Attack1")
local Track = char.Humanoid:LoadAnimation(Attack1)
Track:Play()
for _,anim in pairs(char.Humanoid:GetPlayingAnimationTracks()) do
print(anim.Name)
end
return
NOTE! there are other animations playing with different names but those are of no concern for this test
print returns
-- Client --> Animation
-- Server --> Attack1
I have tried to change the name of the track in the serverscript
Taken from the serverscript
local Attack1 = script.Animations:WaitForChild("Attack1")
local Track = char.Humanoid:LoadAnimation(Attack1)
Track.Name = "TestName"
Track:Play()
print returns
-- Client --> Animation
-- Server --> TestName
Isn't this great you may ask. Now we have the animation even when the server returned nil The problem would occur if you played many animations in the serverscript
-- Client --> Animation, Animation, Animation
-- Server --> Attack1, Attack2, EquipTool
Now how would you get the specific animationtrack because they all have the same name ????
Sincerely: Hakurem

1 comment
Maybe get all the names from the server set the in a table and remote event fire them?