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

How do I make my animation stop when the player clicks it one more time?

Asked by 4 years ago

So I'm trying to make my animation stop when the player clicks it one more time so I have no clue on how to do it here are the lines. It only stops the animation after 1 click it waits for a sec then stops it.

local Player = game.Players.LocalPlayer local Character = Player.Character or script.Parent local Humanoid = Character.Humanoid local UserInputService = game:GetService("UserInputService")

local AnimationId = -- cannot say for reasons

local Key = 'C'

UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[Key] then local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId local LoadAnimation = Humanoid:LoadAnimation(Animation) LoadAnimation:Play() wait(1) if Enum.KeyCode[Key] then wait(0.2) LoadAnimation:Stop() end

end

end)

0
Could you put your code in a code block and format it correctly, because I have no idea what's going on. RealTinCan 217 — 4y
0
Ok sorry cheesepuffman8 0 — 4y
0
In awnsers. cheesepuffman8 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
local Player = game.Players.LocalPlayer
local Character = Player.Character or script.Parent
local Humanoid = Character.Humanoid
local UserInputService = game:GetService("UserInputService")

local AnimationId = --cannot say

local Key = 'C'

UserInputService.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end
    if Input.KeyCode == Enum.KeyCode[Key] then
        local Animation = Instance.new("Animation")
        Animation.AnimationId = AnimationId
        local LoadAnimation = Humanoid:LoadAnimation(Animation)
        LoadAnimation:Play()
        wait(1)
        if Enum.KeyCode[Key] then
            wait(0.2)
            LoadAnimation:Stop()
        end

    end
end)
Ad

Answer this question