Why won't the following code print or change the force? I can not figure it out. This script is a child of a part. For now, when I press E, it should print "E on," but it doesn't. Any Ideas? Thanks, PaliKai
game:GetService("UserInputService").InputBegan:Connect(function(Input, gameprocessed) if Input.KeyCode == Enum.KeyCode.E then script.Parent.BodyForce.Force = Vector3.new(1000, 0, 0) print("E on") end end)
Do the thing with the key held stuff.
```lua
local Array = {}; --array in which we'll be storing keys pressed in via the keycode name. local Test = false game:GetService('UserInputService').InputBegan:Connect(function(henlo, waffle) --why did I name these variables this way? if (not waffle) then -- if a GUI with modal isn't visible, then.. henlo = henlo.KeyCode; --redefine to keycode Array[henlo.Name:upper()] = henlo.Name:upper() --supports multiple keys being pressed. (i think) end end) --on key pressed, this will fire. ```
Do the thing with the release key stuff.
lua
game:GetService('UserInputService').InputEnded:Connect(function(henlotwo) -- we don't need GameProcessedEvent because that will allow people to pull a sneaky on ya and hold a key and alt+tab or hwatever.
henlotwo = henlotwo.KeyCode; --you know, the do.
Array[henlotwo.Name:upper()] = nil; --take it out when not released
end)
Do the test thing do thing variable stuff.
lua
if (Test) then
game:GetService('RunService').RenderStepped:Connect(function(step)
local str = ''
for i, v in pairs(Array) do
str = str..tostring(v)
end
print(str)
end)
end
print(doot doot trumpet trumpet)
an easier method is this
local mouse = game.Players.LocalPlayer:GetMouse() mouse.KeyDown:Connect(function(key) if key.lower() == "e" then --what u want to happen in here end end)
this will only work for clicks and not holds as you are trying to script there i see, but if u want a click instead of a hold then you can go with this script