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

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

Asked by
AizakkuZ 226 Moderation Voter
6 years ago
Edited 6 years ago

****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.

01local Player = game.Players.LocalPlayer
02local Character = Player.Character
03local Humanoid = Character:WaitForChild("Humanoid")
04local Anim4 = Instance.new("Animation")
06local Anim4 = Humanoid:LoadAnimation(Anim4)
07 
08function onKeyDown(inputObject, gameProcessedEvent)
09    if inputObject.KeyCode == Enum.KeyCode.T then
10    print("T was pressed")
11    Anim4:Play()
12    end
13end
14game:GetService("UserInputService").InputBegan:connect(onKeyDown)
0
? AizakkuZ 226 — 6y
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. Ziffixture 6913 — 6y
0
I'm not asking for a script AizakkuZ 226 — 6y
View all comments (4 more)
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 AizakkuZ 226 — 6y
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. Ziffixture 6913 — 6y
0
that is what I did for a double tap w to sprint OBenjOne 190 — 6y
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? AizakkuZ 226 — 6y

Closed as Not Constructive by SerpentineKing and c0des

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago
01local Player = game.Players.LocalPlayer
02local Character = Player.Character
03local Humanoid = Character:WaitForChild("Humanoid")
04local Anim4 = Instance.new("Animation")
06local Anim4 = Humanoid:LoadAnimation(Anim4)
07local keys = 0
08local dbounce = false
09 
10function onKeyDown(inputObject, gameProcessedEvent)
11    if inputObject.KeyCode == Enum.KeyCode.T and dbounce == false then
12    dbounce = true
13    keys = keys + 1
14    function onKeyDown(inputObject, gameProcessedEvent)
15        if inputObject.KeyCode == Enum.KeyCode.T then
View all 27 lines...

this should work or at least close hope this helps

Ad