Recently, i’ve been creating tweens based on certian key inputs which are based on the Piano Key Order.
My issue encounters in the inputEnded function.
Explanation
- While pressing lowercase notes if you press SHIFT and release it at the right moment, this issue will encounter. Making the upper key (shifted key), constantly be the incorrect color. Same goes for opposite and for CTRL
Issues
- The function that should end and revert the colors back is not doing it right.
- There are no error messages whatsoever.
- Tried many methods which include: Remote Event (which handles the tween), Decreasing tween animation time (0), Re-doing the code, etc.
Code Snippet
- InputEnded
if input.UserInputType == Enum.UserInputType.Keyboard and input.UserInputState == Enum.UserInputState.End then
if input.KeyCode == Enum.KeyCode.LeftControl then
EvaluateKeyOrderCTRLPress = false
return
end
if input.KeyCode == Enum.KeyCode.LeftShift then
EvaluateKeyOrderSHIFTPress = false
return
end
--[[
In this line theres a code that is supposed to restrict certian keybinds.
]]
task.wait()
if letter then
EvaluateHitPress(KeyOrderify(letter), false) -- pass function.
end
end
- KeyOrderify
function KeyOrderify(letter)
-- Full 88 keys btw
if EvaluateKeyOrderCTRLPress then
if letter == "1" then
return "-14"
elseif letter == "2" then
return "-13"
elseif letter == "3" then
return "-2"
elseif letter == "r" then
return "-1"
elseif letter == "t" then
return "0"
-- etc...
elseif EvaluateKeyOrderSHIFTPress then
if letter == "1" then
return "2"
elseif letter == "2" then
return "4"
elseif letter == "4" then
return "7"
elseif letter == "5" then
return "9"
elseif letter == "6" then
return "11"
-- etc...
-- White note while also shifting. this is important so it doesn't return nil on these keybinds
if letter == "3" then
return "5"
elseif letter == "7" then
return "12"
elseif letter == "0" then
-- etc...
-- White notes
else
if letter == "1" then
return "1"
elseif letter == "2" then
return "3"
elseif letter == "3" then
else
return nil
end
end
end
Tween Function
function EvaluateHitPress(keylead, phase)
local keyloc -- location to the keys
local fadeTween
if phase == true then -- start
if keyloc:FindFirstChild("Shift") then
fadeTween = TWEEN:Create(keyloc, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0), { BackgroundColor3 = Color3.fromRGB(100, 100, 100) })
fadeTween:Play()
else
fadeTween = TWEEN:Create(keyloc, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0), { BackgroundColor3 = Color3.fromRGB(197, 197, 197) })
fadeTween:Play()
end
else
if keyloc:FindFirstChild("Shift") then -- find if there exists a shift value inside
TWEEN:Create(keyloc, TweenInfo.new(0, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0), { BackgroundColor3 = Color3.fromRGB(6, 6, 6) }):Play()
else
TWEEN:Create(keyloc, TweenInfo.new(0, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0), { BackgroundColor3 = Color3.fromRGB(255, 255, 255) }):Play()
end
end
end
Addition
- One script handles the whole functionality
Video
Let me know what is the issue here, would appreciate it.