Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you ensure that a script replicates a Character.Animate ID change?

Asked by 5 years ago

First thing's first, I know very little about animation in Roblox. This is my first attempt to try and expand my knowledge, and I've come across an issue I can't quite fix. I'm not quite sure if my issue is because of my code, or because of something I don't know of yet involved with animating.

Here's my code:

local character = script.Parent
--//Script is stored in ServerStorage, and at some point, Clone()'d and placed in the player's character
local bool = true
character.Humanoid.WalkSpeed = 10
--//Sets up some basic variables and changes to speed

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=2851176317"
local CustomAnim1 = character.Humanoid:LoadAnimation(animation)

local animation2 = Instance.new("Animation")
animation2.AnimationId = "http://www.roblox.com/Asset?ID=2851319404"
local CustomAnim2 = character.Humanoid:LoadAnimation(animation2)
--//Creates two animation objects, which replicate fine

local function myFunc() --//This gets called elsewhere
    bool = false
    character.Humanoid.WalkSpeed = 1
    character.Head.Sound1:Stop()
    character.Head.Sound2:Play()
    CustomAnim1:Play()
    --//Again, custom animation played this way works fine

    wait(30)

    character.Head.Sound3:Play()
    character.Humanoid.WalkSpeed = 35
    CustomAnim1:Stop()
    script.Active.Value = true

    local humanoid = character:WaitForChild("Humanoid")
    for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
        playingTracks:Stop(0)
    end
    --//No prior animations are used, so stop everything

    local animateScript = character:WaitForChild("Animate")
    animateScript.run.RunAnim.AnimationId = "http://www.roblox.com/Asset?ID=507767714"
    --//Player is currently using the Rthro walk animation, so change the ID in the Animate script to the Rthro run animation ***This only loads for the local client

    CustomAnim2:Play()
    --//Plays my custom upper-body animation perfectly fine 

    wait(25)

    CustomAnim2:Stop()
    --//Custom animation stops

    local humanoid = character:WaitForChild("Humanoid")
    for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
        playingTracks:Stop(0)
    end
    --//All new animations are no longer needed, so stop all of them

    animateScript.run.RunAnim.AnimationId = "http://www.roblox.com/Asset?ID=2851440199"
    --//Since animateScript was already initialized, change the running animation ID back to the Rthro walking animation ID ***This only loads for the local client

    character.Head.Sound3:Stop()
    character.Humanoid.WalkSpeed = 10
    script.Active.Value = false
    wait(10)
    character.Head.Sound1:Play()
    bool = true
    --//Other sound and variable management
end

There are two ways animations are being ran in my script. One of these ways creates Animation objects, loads them into the player's Humanoid, and when I set the script to, :Play()'s it. These play for everyone, and seem to work fine. These animations however, are supposed to only affect the upper torso (R15) and arm bits, while leaving the legs handled by the default Roblox Rthro walk & run animations. This is where my issue arises. On my client, I can see my custom anims playing over the walk (and then run) anims just fine, but to every other player, I lack any leg animation whatsoever and just slide around. I suppose I could use the prior method of playing animations to force a walk animation on the Humanoid, but then the walk cycle would continue if the player stopped moving, and I want to avoid that.

Since only the local player sees the animations, I'd assume it was a replication error, but I'm using a Script (not a LocalScript), so I'd think that these changes would be replicated regardless. I've seen some people with similar issues, but they never seem to have any resolutions. Any help would be greatly appreciated!

1 answer

Log in to vote
0
Answered by 3 years ago

I know you posted this about a year ago but I just wanted to say your the most talented scripter ive ever seen. I look up to you.

Ad

Answer this question