Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

trying to make the Animation play randomly when actives but it wont work how do i fix?

local player = game.Players.LocalPlayer 
local mouse = player:GetMouse()
local hum = player.Character.Humanoid
local attack = true
script.Parent.Activated:Connect(function()
local rpick = math.random(0,3)
    local hopethisworks = player.Character.Humanoid:LoadAnimation(script.Parent.Animation1 or script.Parent.Animation2 )  
hopethisworks.Priority = Enum.AnimationPriority.Action 
hopethisworks:Play() 


script.Parent.Handle.Touched:Connect(function(hit)

    local player = game.Players.LocalPlayer

local handle = script.Parent.Handle



local hum = hit.Parent:FindFirstChild("Humanoid")
if hum and attack == true then
    hum:TakeDamage(12)
    attack = false
end


end)
wait(1)
 attack = true
end)

2 comments

0

please provide more information in your question

0

its only plays one Animation i wanted to play more than one but randomly

1 answer

✓ Accepted answer

You can define both animations into separate variables and put them into a table. Then, math.random() an animation from the table. After that, load and play the randomed animation.

local player = game.Players.LocalPlayer 
local mouse = player:GetMouse()
local hum = player.Character.Humanoid
local attack = true

--Defining variables for each animation.
local anim1 = script.Parent.Animation1
local anim2 = script.Parent.Animation2

--Put the animations into a table.
local anims = {anim1, anim2}


script.Parent.Activated:Connect(function()
--Pick an animation from the animation table.
	local pickedanim= anim[math.random(1,#anims)]

   	local hopethisworks = player.Character.Humanoid:LoadAnimation(pickedanim)
	hopethisworks.Priority = Enum.AnimationPriority.Action 
	hopethisworks:Play() 


script.Parent.Handle.Touched:Connect(function(hit)

    local player = game.Players.LocalPlayer

local handle = script.Parent.Handle



local hum = hit.Parent:FindFirstChild("Humanoid")
if hum and attack == true then
    hum:TakeDamage(12)
    attack = false
end


end)
wait(1)
 attack = true
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.