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
5 years ago
Edited 5 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.

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)

0
? AizakkuZ 226 — 5y
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 — 5y
0
I'm not asking for a script AizakkuZ 226 — 5y
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 — 5y
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 — 5y
0
that is what I did for a double tap w to sprint OBenjOne 190 — 5y
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 — 5y

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 5 years ago
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

Ad