I am trying to make something where if you touch a part, you can then press a key and that prints something, but I am still fairly new to the whole UserInputService, so I am not sure how to do about doing it. Here's the code:
script.Parent.Touched:connect(function(hit)
function onKeyPress(inputObject, gameProcessedEvent)
if script.Parent.Touched and inputObject.KeyCode == Enum.KeyCode.Q then
local h = hit.Parent
h.Torso.CFrame = CFrame.new(part.Position.X, h.Torso.Position.Y, h.Torso.Position.Z)
print("Touched")
end
end
end)
keypressConnect = game:GetService("UserInputService").InputBegan:connect(onKeyPress)
|