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

How can I make this animation on this tool a Click animation on a mouse?

Asked by
dog6779 25
6 years ago
Edited 6 years ago

So here is the script:

local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/Asset?ID=1438749801"

local trackanimation = nil
local playability = true
function playAnimation(AnimationSource)
    if playability == true then
        local plr = game.Players.LocalPlayer
        trackanimation = plr.Character.Humanoid:LoadAnimation(animation)

          trackanimation.KeyframeReached:connect(function()
            print ('Working')
        end)
        trackanimation:Play()
    end
end

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local waituntilback = script.Parent.Parent.Tool.Equipped:connect()
script.Parent.Parent.Tool.Equipped:connect(function()
    if not script.Parent.Parent.Tool.Equipped:connect() then
        playAnimation(waituntilback) else
        playAnimation()     
    end
end)

But how do I make it where it shows up in the game and How do I make it where it's only a Mouse click. This script only when you pull out the tool it starts the animation.

1 answer

Log in to vote
0
Answered by 6 years ago
-- make sure the change the animationId value in the tool!
wait(0.5)
local Tool = script.Parent
local AnimationId = Tool.AnimationId.Value
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Cooldown = false
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..AnimationId
Animation.Parent = Humanoid
Tool.Activated:Connect(function()
    local Anim = Humanoid:LoadAnimation(Animation)
    Anim:Play()
end) -- put a IntValue in the tool and name it AnimationId then just paste the id of the animation you want in the IntValue number label.

0
Okay, so the script you gave me is working but when I saw this in the script analysis it said this: W003: (9,5) Global 'y' is only used in the enclosing function; consider changing it to local. W003: (10,5) Global 'z' is only used in the enclosing function; consider changing it to local. dog6779 25 — 6y
Ad

Answer this question