Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

Could you put your code in a code block and format it correctly, because I have no idea what's going on.

0

Ok sorry

0

In awnsers.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.