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

Animation script for tool not working when equipped and clicked?

Asked by 6 years ago

I made an animation script for a cup, and When the player has the tool equipped, and the player clicks it plays the animation. But it doesnt work.

things to know -- Animis the name of the animation and it is inside the script. Tool is a cup. here is my script

local Tool = script.Parent
local Anim = nil
local Ready = true

Tool.Activated:Connect(function()
    if Tool.Parent.Humanoid.Health > 0 and Ready == true then
        Ready = false
        Anim = Tool.Parent.Humanoid:LoadAnimation(script:WaitForChild("Anim"))
        Anim:Play()
        wait(2)
        Ready = true
    end
end)

Tool.Unequipped:Connect(function()
    if Anim then Anim:Stop() end
    Ready = true
end)

1 answer

Log in to vote
0
Answered by 6 years ago

Next time explain your question please, for example;

Is there any errors?

Have you checked the output?

etc.

The only thing I can suggest is to name the animation differently and place it somewhere else like ReplicatedStorage

I will re-write the script but make sure the Animation is named "CupAnimation" and it placed in ReplicatedStorage

Script;

local Cup = script.Parent
local CupAnime = game.ReplicatedStorage:WaitForChild('CupAnimation')
local Ready = true

Cup.Activated:Connect(function() -- use Connect with cap C
    if Cup.Parent.Parent:WaitForChild('Humanoid').Health >= 1 then
        local plr = Cup.Parent.Parent
        if Ready = true then
            Ready = false
            local LoadAnime = plr:WaitForChild('Humanoid'):LoadAnimation(CupAnime)
            LoadAnime:Play() -- if it doesn't work change to CupAnime:Play()
            wait(2)
            Ready = true
        end
    end
end)

Tool.Unequipped:Connect(function()
    Anim:Stop()
    Ready = true
end)

Now I Wrote this from scratch; here;s a few things you can try if it STILL Doesn't work;

  1. Change LoadAnime:Play() with CupAnime:Play()

  2. Change Cup.Parent.Parent:WaitForChild('Humanoid').Health >= 1 then to Cup.Parent.:WaitForChild('Humanoid').Health >= 1 then (deletes a parent) AND Change local plr = Cup.Parent.Parent to local plr = Cup.Parent

  3. Make sure animation is in Replicated Storage and make sure everything is correct (in variables)

Hope this helped, if helped then Please upvote and accept answer ;)

Good luck have fun developing!

Ad

Answer this question