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
local UserInputService = game:GetService("UserInputService") local Tool = script.Parent local Player = game.Players.LocalPlayer local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid") UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://NoSeesLol" local Track = Humanoid:LoadAnimation(Animation) Track:Play() end end)
local UserInputService = game:GetService("UserInputService") local Tool = script.Parent local Player = game.Players.LocalPlayer local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid") local Animations = {"animationid_1","animationid_2","animationid_3","animationid_4",} UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then local RandomAnimation = Animations[math.random(1,#Animations)] local ChosenId = RandomAnimation print(RandomAnimation) local Animation = Instance.new("Animation") Animation.AnimationId = ChosenId local Track = Humanoid:LoadAnimation(Animation) Track:Play() end end)
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.
local UserInputService = game:GetService("UserInputService") local Tool = script.Parent local Player = game.Players.LocalPlayer local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid") UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then local numberofanims = 3 --put how many animations you have local num = math.random(1,numberofanims) if num == 1 then local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://NoSeesLol" local Track = Humanoid:LoadAnimation(Animation) Track:Play() elseif num == 2 then local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://NoSeesLol" local Track = Humanoid:LoadAnimation(Animation) Track:Play() elseif num == 3 then local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://NoSeesLol" local Track = Humanoid:LoadAnimation(Animation) Track:Play() end end end)