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

No error codes but its still not working, and the animation doesnt play?

Asked by
FBS_8 25
4 years ago

localscript:

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4975456908"
anim.Name = "TauntAnim"

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:Connect(function(key)
    if key == "E" and tool.Equipped then
        anim:Play()
    end
end)

mouse.KeyUp:Connect(function(key)
    if key == "E" and tool.Equipped then
        anim:Stop()
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You have to load the animation first. Also, I'd use UserInputService.

local UserInputService = game:GetService("UserInputService")

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4975456908"
anim.Name = "TauntAnim"
anim.Parent = script

local tool = script.Parent
local player = game.Players.LocalPlayer

local clicked = false

local loadedAnim

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.E then
        loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
        loadedAnim:Play()
    end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
    if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.E then
        if loadedAnim then
            loadedAnim:Stop()
        end
    end
end)

The InputBegan event fires when an input begins (keyboard, mouse, etc.) Then there's an if statement checking if the player is not in chat, and if the input is "E" on their keyboard. Then the loadedAnimation plays. The InputEnded is the same thing but it stops the animation.

Ad

Answer this question