Recently I’ve been trying to make a custom in-game NohBoard in one of my games. I was able to program one with the W, A, S, D, and space keys with the help of a few other people on the forum, but as soon as I started adding shift lock a ton of things started going wrong.
The issue I’m having is that it seems the W, A, S, D, and space keys all do the thing I intended the shift lock key to do, and vice versa. Another huge problem I’ve noticed is that if you press any other key that isnt those 7 (those 5 keys plus left and right shift), you get a massive lagspike out of nowhere.
Here is a video of the issue I’m having (I didn’t record the lagging issue, but it’s pretty self explanitory:
External MediaNotice how when I tap the W, A, S, D, or space keys the gui only disappears once you tap it again (which was intended for the shift keys), and when you tap shift the gui disappears when you let go of the key (was was intended for the other 5 keys). All of the keys also seem to only activate the shift gui, not the other 5 guis I’ve made… strange.
Here is the code for anyone who wants to look into it:
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local userInput = game:GetService("UserInputService")
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local camera = workspace.CurrentCamera
local keycodeToGui = {
[Enum.KeyCode.W] = playerGui:WaitForChild("NohboardW"),
[Enum.KeyCode.A] = playerGui:WaitForChild("NohboardA"),
[Enum.KeyCode.S] = playerGui:WaitForChild("NohboardS"),
[Enum.KeyCode.D] = playerGui:WaitForChild("NohboardD"),
[Enum.KeyCode.Space] = playerGui:WaitForChild("NohboardSpace"),
[Enum.KeyCode.LeftShift] = playerGui:WaitForChild("NohboardShift"),
[Enum.KeyCode.RightShift] = playerGui:WaitForChild("NohboardShift")
}
-- we can loop through a table and set all of them to false
-- save the copy and paste
for _, ui in keycodeToGui do
ui.Enabled = false
end
run.RenderStepped:Connect(function()
local distance = (head.Position - camera.CFrame.Position).Magnitude
local debounce = false
local function checkKeys()
userInput.InputBegan:Connect(function(input)
if keycodeToGui[input.KeyCode] then -- check if the key exists
if Enum.KeyCode.LeftShift or Enum.KeyCode.RightShift then -- is the player pressing either of the shift keys?
if distance > 0.55 then
if debounce == false then -- not in first person and turns on shift lock, turns on gui
playerGui.NohboardShift.Enabled = true
debounce = true
else -- not in first person and turns off shift lock, turns off gui
playerGui.NohboardShift.Enabled = false
debounce = false
end
end
else -- if not, enable the other keys from the table above
keycodeToGui[input.KeyCode].Enabled = true -- set the respective gui to be enabled
end
end
end)
if distance < 0.55 then -- constantly checking: is the player in first person? if yes, turn off the shift lock gui
playerGui.NohboardShift.Enabled = false
else
if debounce == true then
playerGui.NohboardShift.Enabled = true -- if the player is in shiftlock, zoomed to first person, and zooms back out, turn the gui on again
end
end
userInput.InputEnded:Connect(function(input)
if keycodeToGui[input.KeyCode] ~= Enum.KeyCode.LeftShift or Enum.KeyCode.RightShift then
keycodeToGui[input.KeyCode].Enabled = false
end
end)
end
checkKeys()
end)
Please keep in mind that I’m fairly new to scripting, so if this makes you want to rip your eyeballs out I wouldn’t blame you
Any and all help is appreciated!