What do you want to achieve? Keep it simple and clear!
i want to get the keybind from a button, then when that keybind is pressed make it increment a value upward or downward.
What is the issue? Include screenshots / videos if possible!
a bunch of errors and idk how to continue
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried reading the errors but they make no sense, assistant also isn’t helping. No i didn’t look for solutions on the devforum
local gun = GetPartFromPort(0, "TriggerWire")
local turretx = GetPartFromPort(1, "Servo")
local turrety = GetPartFromPort(2, "Servo")
local button = GetPart("Button")
if button.Key == W then button.Click:Connect(function() clicked() end);
end
i didn’t know about the button.Click:Connect(function() clicked() end); btw, so i dont know how it works, i asked someone else and they told me just to use it
what
its just a button, the microcontroller grabs it and then if it detects a certain keybind it’ll do a certain thing
so if its keybind W it’ll do SetAngle(+1) and make the turret move upward vice versa with keybind S.
It is detecting when the button is pressed so
ok, i got told to use lua Button:GetComponent("KeyButton"):GetConfigurable("Key")
how do i make it so i can check key, cause lua if "Key" is isn’t working
local gun = GetPartFromPort(0, "TriggerWire")
local turretx = GetPartFromPort(1, "Servo")
local turrety = GetPartFromPort(2, "Servo")
local Button = GetPart("Button")
Button:GetComponent("KeyButton"):GetConfigurable("Key")
if "Key" == "W" then
turrety.SetAngle(turrety.Angle + 1)
end
if "Key" == "S" then
turrety.SetAngle(turrety.Angle - 1)
end
if "Key" == "D" then
turretx.SetAngle(turretx.Angle + 1)
end
if "Key" == "A" then
turretx.SetAngle(turretx.Angle - 1)
end
if "Key" == "F" then while true do
TriggerPort(0)
end
ok I got told to use a keyboard instead of buttons
local gun = GetPartFromPort(0, "TriggerWire")
local turretx = GetPartFromPort(1, "Servo")
local turrety = GetPartFromPort(2, "Servo")
local Keyboard = GetPart("Keyboard")
local goal = 0
if KeyPressed(42518419, "W" ) then
turrety:SetAngle(goal + 1)
end
if KeyPressed(42518419, "S" ) then
turrety:SetAngle(goal - 1)
end
if KeyPressed(42518419, "A" ) then
turretx:SetAngle(goal + 1)
end
if KeyPressed(42518419, "D" ) then
turretx:SetAngle(goal - 1)
end
if KeyPressed(42518419, "F" ) then
TriggerPort(0)
end
while true do
task.wait(1)
end
local gun = assert(GetPartFromPort(0, "Gun"), "no gun")
local turretx = assert(GetPartFromPort(1, "Servo"), "no turret x")
local turrety = assert(GetPartFromPort(2, "Servo"), "no turret y")
local keyboard = assert(GetPart("Keyboard"), "no keyboard")
local goal = 0
local goal1 = 0
local whitelist = {
[42518419] = true,
}
local BINDS = {
[Enum.KeyCode.W] = function()
print("W")
while Enum.KeyCode.W == true do
goal += 1
end
turrety:SetAngle(goal)
end,
[Enum.KeyCode.A] = function()
print("A")
while Enum.KeyCode.A == true do
goal1 += 1
end
turretx:SetAngle(goal1)
end,
[Enum.KeyCode.S] = function()
print("S")
while Enum.KeyCode.S == true do
goal -= 1
end
turrety:SetAngle(goal)
end,
[Enum.KeyCode.D] = function()
print("D")
while Enum.KeyCode.D == true do
goal1 -= 1
end
turretx:SetAngle(goal1)
end,
[Enum.KeyCode.F] = function()
TriggerPort(0)
end,
}
keyboard.KeyPressed:Connect(function(key, _, userId)
if not whitelist[42518419] then return end
local callback = BINDS[key]
if not callback then return end
callback()
print(goal)
print(goal1)
end)
ok apparently the solution is some overcomplicated piece of code.
this sucks, i really hate scripting and never wish that anyone goes through this garbage again.
these while true do loops don’t even loop, i asked why and i get some stupid “its a enum that’s being set to true” response as if that tells me why they’re not looping
woscord has a really awful community when it comes to asking microcontroller questions, but after a hour+ of arguing my problem is finally solved
local gun = assert(GetPartFromPort(0, "Gun"), "no gun")
local turretx = assert(GetPartFromPort(1, "Servo"), "no turret x")
local turrety = assert(GetPartFromPort(2, "Servo"), "no turret y")
local keyboard = assert(GetPart("Keyboard"), "no keyboard")
local goal = 0
local goal1 = 0
local keys = {
[Enum.KeyCode.W] = 0;
[Enum.KeyCode.A] = 0;
[Enum.KeyCode.S] = 0;
[Enum.KeyCode.D] = 0;
}
local whitelist = {
[42518419] = true,
}
local pBINDS = { --pBINDS is for special functions that are called when a key is pressed
[Enum.KeyCode.F] = function()
TriggerPort(0)
end,
}
keyboard.UserInput:Connect(function(input, userId)
if not whitelist[userId] then return end
if keys[input.KeyCode] then
if input.UserInputState == Enum.UserInputState.Begin then
keys[input.KeyCode] = 1
elseif input.UserInputState == Enum.UserInputState.End then
keys[input.KeyCode] = 0
end
end
local callback = pBINDS[input.KeyCode]
if not callback then return end
callback()
print(goal)
print(goal1)
end)
while true do
goal += (keys[Enum.KeyCode.W] - keys[Enum.KeyCode.S])
goal1 += (keys[Enum.KeyCode.A] - keys[Enum.KeyCode.D])
turrety:SetAngle(goal)
turretx:SetAngle(goal1)
task.wait()
end
Hey, sorry you were having a tough time getting help from the community. I know how frustrating it can be when people aren’t being helpful or are being intentionally vague with their answers. If you encounter someone who is being intentionally not helpful, please ping a moderator so they can take appropriate action against those who aren’t creating a welcoming experience. Hopefully you are having a better time with the game, have fun!