You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like to be able to get when the player is touching the part AND clicking “E”
What is the issue? Include screenshots / videos if possible!
It doesn’t give me the print as if the player has never clicked E.
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
local function Clicked()
end
UserInputService.InputBegan:Connect(function(key)
print ("Try")
if key.KeyCode == Enum.KeyCode.E then
Part.Touched:Connect(Clicked)
end
end)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Found nothing
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
local function Clicked(otherPart)
print("Clicked")
end
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
Part.Touched:Connect(Clicked)
end
end)
From what I understood I assume you want to check if the player is pressing E when your part is touched.
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
local function Clicked()
if UserInputService:IsKeyDown(Enum.KeyCode.E) do
--Code goes here
end
end
Part.Touched:Connect(Clicked)
local UserInputService = game:GetService("UserInputService")
local Part : BasePart = script.Parent
local isTouching = false
Part.Touched:Connect(function() isTouching = true end)
Part.TouchEnded:Connect(function() isTouching = false end)
local function Clicked()
end
UserInputService.InputBegan:Connect(function(key)
print ("Try")
if key.KeyCode == Enum.KeyCode.E and isTouching == true then
end
end)
You can check if the touched part is a part of the player.
local uis = game:GetService("UserInputService")
local Part = workspace.Part -- put the part here
local function istouching(part)
for _, part in pairs(part:GetTouchingParts()) do
if part:IsDescendantOf(game.Players.LocalPlayer.Character) then
return true
end
end
end
uis.InputBegan:Connect(function(input)
print("Pressed key", input.KeyCode.Name)
if key.KeyCode == Enum.KeyCode.E and isTouching() then
print("Pressed E, and touching part!")
end
end)