I am trying to detect if a player is touching a part and if the player presses a key something happens. I get no errors and nothing happens when I am touching the part and I press E.
My attempt:
local part = script.Parent
local function onPartTouched(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
print("E was pressed")
end
end)
end
end
part.Touched:Connect(onPartTouched)

3 comments
is it in a localscript?
@NeonPandaEyes331 No, it is in a server script.
@NeonPandaEyes 331 I also tried it in a LocalScript it still does not work.