animateScript.jump.JumpAnim.AnimationId = "rbxassetid://5620182994" -- Jump animateScript.jump.JumpAnim.AnimationId = "rbxassetid://5620201065" -- Jump2
This is the part of the code that isn't working. Roblox Developer Wiki says that it should be random, but it only plays 1 the entire time. I want it to play one or the other at random. Help!
You can simply use math.random().
while wait() do local random = math.random(1, 2) if random == 1 then animateScript.jump.JumpAnim.AnimationId = "rbxassetid://5620182994" else animateScript.jump.JumpAnim.AnimationId = "rbxassetid://5620201065" end end
Lemme know if it works!
You can check for player state when the player jumps. If the new state is Enum.HumanoidStateType.Jumping
, they're jumping! This means you can reselect another animation randomly each time they jumps.
Use LocalScript for this.
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() --Waits for their character to get their humanoid local hum = char:WaitForChild('Humanoid') --again, wait for their humanoid if it's not loaded yet local anims = { "rbxassetid://5620182994", "rbxassetid://5620201065" } local animObj = animateScript.jump.JumpAnim --Your animation object here. local changeAnimation = { [Enum.HumanoidStateType.Jumping] = true --You can add more states here if you want multiple states to run animation rotation. --If you don't want any more states, use Humanoid.Jump event instead. } --Humanoid.StateChanged -> (oldState, newState) --no need oldState for this hum.StateChanged:Connect(function(_, newState) --Use dictionary indexing to find if this is the state you want the animation to be updated the next time you jump. if changeAnimation[newState] then --Use math.random! animObj.AnimationId = anims[math.random(1, #anims)] --This gets one animation id and update the AnimationId property. end end)
Just to make sure, you should use humanoid:LoadAnimation(animationObject) in case you want to play this animation yourself when the player jumps.