So currently I have some code that plays an animation when mousebutton1 is down, but I want it to have alternate animations. I want it to be randomized, so that each time I press the mouse button it plays a different animation. Here's my code
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local Tool = script.Parent |
03 | local Player = game.Players.LocalPlayer |
04 | local Character = Player.Character |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 |
07 | UserInputService.InputBegan:Connect( function (InputObject) |
08 | if InputObject.UserInputType = = Enum.UserInputType.MouseButton 1 then |
09 | local Animation = Instance.new( "Animation" ) |
10 | Animation.AnimationId = "rbxassetid://NoSeesLol" |
11 | local Track = Humanoid:LoadAnimation(Animation) |
12 | Track:Play() |
13 | end |
14 | end ) |
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local Tool = script.Parent |
03 | local Player = game.Players.LocalPlayer |
04 | local Character = Player.Character |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 |
07 | local Animations = { "animationid_1" , "animationid_2" , "animationid_3" , "animationid_4" , } |
08 |
09 | UserInputService.InputBegan:Connect( function (InputObject) |
10 | if InputObject.UserInputType = = Enum.UserInputType.MouseButton 1 then |
11 |
12 | local RandomAnimation = Animations [ math.random( 1 ,#Animations) ] |
13 | local ChosenId = RandomAnimation |
14 |
15 | print (RandomAnimation) |
i think this works, just make sure to add the animation id's in the "Animation" table.
I'm on my phone so I can't test it.
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local Tool = script.Parent |
03 | local Player = game.Players.LocalPlayer |
04 | local Character = Player.Character |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 |
07 | UserInputService.InputBegan:Connect( function (InputObject) |
08 | if InputObject.UserInputType = = Enum.UserInputType.MouseButton 1 then |
09 | local numberofanims = 3 --put how many animations you have |
10 | local num = math.random( 1 ,numberofanims) |
11 | if num = = 1 then |
12 | local Animation = Instance.new( "Animation" ) |
13 | Animation.AnimationId = "rbxassetid://NoSeesLol" |
14 | local Track = Humanoid:LoadAnimation(Animation) |
15 | Track:Play() |