✓ Accepted answer
Well if I completely understand what you are asking, to clarify, you want to detect a users input if they are touching a part?
If so, try something like this:
(When I say "something" it would just be this general concept, I am not sure if the touch works on client or if you need to check if the localplayer is the other part)
local istouching = false
local function onKeyPress(inputObject, gameProcessedEvent)
if istouching then
end
end
local function touchStart()
istouching = true
end
local function touchEnded()
istouching = false
end
workspace.part.Touched:connect(touchStart)
workspace.part.TouchEnded:connect(touchEnded)
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
It should be pretty straight forward, if you would like more of an explanation then just ask.
If this is not what you were asking, please clarify.
Best of luck
Edit:
Possibly, another way of doing this would be:
local keypresscon = nil
local function onKeyPress(inputObject, gameProcessedEvent)
end
local function touchStart()
if keypresscon ~= nil and keypresscon.Disconnect ~= nil then keypresscon:Disconnect() end
keypresscon = game:GetService("UserInputService").InputBegan:connect(onKeyPress)
end
local function touchEnded()
if keypresscon ~= nil and keypresscon.Disconnect ~= nil then keypresscon:Disconnect() end
end
workspace.part.Touched:connect(touchStart)
workspace.part.TouchEnded:connect(touchEnded)
This would just create the connection when the player starts touching the part, and then destroy it when it ends, pretty straight forward, again.
All of this is untested. Sorry for any bugs
2 comments
Thank you. I have tested it, added an extra end to it but it works! Thank you!
Of course!