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

Local Script Key Down Events (Short and Simplified)?

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

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!

1 comment

0

thank you

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