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

How to make it when u click a key twice it plays a different animation oppose to clicking once?

Sorry if the title sounds weird it's the 100 character limit This is apart of a script in a game I'm making, the original script takes a sword from a sheath that is attached to the player via welding and, it makes the sword weld to the player's hand whilst playing this animation but, that doesn't matter so I narrowed it down so u can focus on the only parts you need to focus on to answer this question for me.

This is the script, it's a simple script that plays an animation when a key is pressed but I can't figure out how to make it so if I clicked the key twice it would play a different animation in my case put the sword back in the sheath.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Anim4 = Instance.new("Animation")
Anim4.AnimationId = "http://www.roblox.com/Asset?ID=02919926374"
local Anim4 = Humanoid:LoadAnimation(Anim4)

function onKeyDown(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.T then
	print("T was pressed")
	Anim4:Play()
	end
end
game:GetService("UserInputService").InputBegan:connect(onKeyDown)

8 comments

0

?

0

We are not going to hand a Script to you without evidence of an attempt or an issue regarding the attempt. Try first, or contact ROBLOX Support, as we are not them.

0

I'm not asking for a script

0

I'm asking how would I use something like if and then to make it so if I click T twice it would play another animation using the same function

1

Okay then, take this: Store last key, use a tick timestamp for .5 second combo window, compare 'LastKey' to the new Key. Run separate Code based on the recorded Input.

0

that is what I did for a double tap w to sprint

0

So store last key and if the last key was the same as the new key then make it run whatever in my case a new animation?

1 answer

✓ Accepted answer
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Anim4 = Instance.new("Animation")
Anim4.AnimationId = "http://www.roblox.com/Asset?ID=02919926374"
local Anim4 = Humanoid:LoadAnimation(Anim4)
local keys = 0
local dbounce = false

function onKeyDown(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.T and dbounce == false then
    dbounce = true
    keys = keys + 1
    function onKeyDown(inputObject, gameProcessedEvent)
	    if inputObject.KeyCode == Enum.KeyCode.T then
	    	keys = keys + 1
	    end
    end)
    wait(1)
    if keys = 2 then
    animation code here
    end
    print("T was pressed")
    Anim4:Play()
    end
end
game:GetService("UserInputService").InputBegan:connect(onKeyDown)

this should work or at least close hope this helps

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