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

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

Asked by 5 years ago
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)
0
please provide more information in your question BenSBk 781 — 5y
0
its only plays one Animation i wanted to play more than one but randomly helleric -3 — 5y

1 answer

Log in to vote
1
Answered by
Rheines 661 Moderation Voter
5 years ago

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)
Ad

Answer this question