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

A Few Random Questions About Lua [?]

Asked by 6 years ago

So I just wanted to know a few stuff about lua, here are my questions;

  1. How Would I Do Key Code Combinations?

My best guess for this question is something like this;

local uis = game:GetService('UserInputService')

uis.InputBegan:Connect(function(input)
    if input = Enum.KeyCode.Z and if input = Enum.KeyCode.Y then
        --code
    end
end)

So I'm not sure.

  1. How would I make it so that if a person presses this KeyCode a certain amount of times in a certain time?

So I would say something like press W twice to sprint but he has to press it within 2 seconds?

  1. How Would I Detect If a player is Holding A key down or Holding a click?

I have absolutely no idea on how. But I know it's possible because in some games you can charge stuff my holding.

Please help me.

Thank you for reading.

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
6 years ago

1.

With this list on the wiki.

2.

Use tick(). If you don't know, tick returns the current unix time. Unix time is the number of seconds since January 1, 1970 and is how computers tell time. You can use this and subtraction to find out how long something took.

local lastInput = tick()

uis.InputBegan:Connect(function(input)
    if tick() - lastInput <= 2 then
        print("double click")
    end

    lastInput = tick()
end)

3.

That's ez pz. When the input begins, set a boolean to true. When the input ends, set it to false. Now you just have to check that value.

Ad

Answer this question