What do you want to achieve? I want to create customizable controls
What is the issue? I put in a key name and it doesn’t work
What solutions have you tried so far? I tried looking up on YouTube and even the fourm but nothing works
Script(Located in StarterCharacterScripts):
local UIS = game:GetService("UserInputService")
local Key = game.StarterGui.ScreenGui.TextBox.Text
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Key then
print("Key Pressed!")
end
end)
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.E --Or whatever you want.
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Key then
print("Key Pressed!")
end
end)
If you want it to use the name of a KeyCode, you have to use if Input.KeyCode.Name == Key
Also, your code wouldn’t work anyways since you’re getting the Text of TextBox once, do this
local UIS = game:GetService("UserInputService")
local Key = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode.Name == Key.Text then
print("Key Pressed!")
end
end)
Edit: Thank you @Jermartynojm for pointing out the flaw in my code, it has been fixed now
Actually your code won’t work 100% good. Here’s what you should do in LocalScript:
local UIS = game:GetService("UserInputService")
local Key = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox --I made change in this line.
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode.Name == Key.Text then
print("Key Pressed!")
end
end)
local UIS = game:GetService("UserInputService")
local Key = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[Key.Text] then --I changed stuff here.
print("Key Pressed!")
end
end)