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

Local Script Key Down Events (Short and Simplified)?

Asked by 9 years ago
local Left= coroutine.create(function (key)
if key=="z" then
    if c.Lanes.Lane1.A1.Position.Y.Scale >=0.202 or c.Lanes.Lane1.A1 == false then -- could this work?
       Bad() print'Bad'
    elseif c.Lanes.Lane1.A1.Position.Y.Scale >= 0 and c.Lanes.Lane1.A1.Position.Y.Scale <= 0.161 then 
        Cool1() CC1() print'cool' 
    elseif  c.Lanes.Lane1.A1.Position.Y.Scale >= 0 and c.Lanes.Lane1.A1.Position.Y.Scale<= 0.059 then
        Perfect1()CC1() print 'Perfect'end end end)

then ...

Mouse.KeyDown:connect(Left) 
Mouse.KeyDown:connect(Down)
Mouse.KeyDown:connect(Right)
Mouse.KeyDown:connect(Up)

Basically I am trying to make a dance dance revolution game. For some reason the key events aren't detected. Everything else works fine. Hierarchy is also ok.

then functions Bad() Cool1() CC1() and Perfect1() Also work. Im trying to run the movement of a frame while being able to recognize key pressing simultaneously that is why i am using coroutines.

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

First of all, please format your code with standard indentation. That blob you posted above is very hard to read.

Events in ROBLOX are already given their own thread when the connected event is fired. Luckily for you, that means you can use a single function for all four inputs without issue.

local handleInput = function (key)
    key = key:lower() --so holding Shift doesn't affect the if statements below.
    if key == "z" then
        if c.Lanes.Lane1.A1.Position.Y.Scale >= 0.202 or not c.Lanes.Lane1:FindFirstChild("A1") then --I assume this is what you mean by == false?
            Bad()
            print'Bad'
        elseif c.Lanes.Lane1.A1.Position.Y.Scale >= 0 and c.Lanes.Lane1.A1.Position.Y.Scale <= 0.161 then 
            Cool1()
            CC1()
            print'cool' 
        elseif  c.Lanes.Lane1.A1.Position.Y.Scale >= 0 and c.Lanes.Lane1.A1.Position.Y.Scale <= 0.059 then
            Perfect1()
            CC1()
            print 'Perfect'
        end
    elseif key == "x" then
        --code
    elseif key == "c" then

    elseif key == "v" then

    end --And so on, if you have any more...
end

Mouse.KeyDown:connect(handleInput)

Also, instead of using KeyDown, which is deprecated, try using the UserInputService instead!

0
thank you SamDomino 65 — 9y
Ad

Answer this question