So I’m making a sprint script that uses the key to sprint that the player has manually assigned with their keyboard, and when I press left shift (default keycode), for some reason, it shows as a blank space in the sprinting script error?
The setting button code:
local button = script.Parent
local UIS = game:GetService('UserInputService')
local canyaclick = true
button.MouseButton1Down:Connect(function()
if canyaclick then
canyaclick = false
lol = UIS.InputBegan:Connect(function(i,g)
if not g and i.KeyCode then
lol:Disconnect()
local lekey = UIS:GetStringForKeyCode(i.KeyCode)
button.Text = "sprint key; ".. lekey
print("key-"..lekey)
script.Parent.Parent.Parent.Parent.Noreset.SprintKey.Value = UIS:GetStringForKeyCode(i.KeyCode)
canyaclick = true
end
end)
end
end)
This is really infuriating because every other keycode works… what’d I do wrong?
It seems to be a problem with GetStringForKeyCode, I think it’s only meant to handle letters and not special keys like shift and enter. You can replace it with i.KeyCode.Name.
local button = script.Parent
local UIS = game:GetService('UserInputService')
local canyaclick = true
button.MouseButton1Down:Connect(function()
if canyaclick then
canyaclick = false
lol = UIS.InputBegan:Connect(function(i,g)
if not g then return end
local lekey = UIS:GetStringForKeyCode(i.KeyCode)
button.Text = "sprint key; ".. lekey
print("key-"..lekey)
script.Parent.Parent.Parent.Parent.Noreset.SprintKey.Value = UIS:GetStringForKeyCode(i.KeyCode)
canyaclick = true
end)
end
end)
I think the not is accounting for the keycode too.
local button = script.Parent
local UIS = game:GetService('UserInputService')
local canyaclick = true
button.MouseButton1Down:Connect(function()
if canyaclick then
canyaclick = false
lol = UIS.InputBegan:Connect(function(i,g)
if not g and i.KeyCode then
lol:Disconnect()
local lekey = UIS:GetStringForKeyCode(i.KeyCode)
lekey = lekey.Name
button.Text = "sprint key; ".. lekey
print("key-"..lekey)
script.Parent.Parent.Parent.Parent.Noreset.SprintKey.Value = lekey
canyaclick = true
end
end)
end
end)
It doesn’t look like the error comes from the code you posted, Enum.KeyCode is never accessed.
Going to take a guess and say that you might doing something like this in another script to check if the sprint key is being pressed:
-- Noreset.SprintKey.Value is set on line 14 of the code provided to "" (an empty string)
if input.KeyCode == Enum.KeyCode[Noreset.SprintKey.Value] then
--- Sprint
end
Which is what’s actually causing the error. @Judgy_Oreo’s suggestion of using the Enum’s name instead is probably the best solution.