Note this is my first post so sorry if I do things wrong
Anyways I’ve been working on some stuff in studio and I was wondering if it is possible to do some sort of UIS and touched thing like if a part is touching another part and the player is doing some user input stuff I could do something?
You would set a variable to true when the player begins the input and false when the player ends the input. Then for the Touched event you would check if the variable is true and run the code if it’s true.
You can simply check if a key is held down when the .Touched event fires:
--Must be in a local script on the client
--due to checking for input, unless you use remotes
touchPart.Touched:Connect(function(part)
if UserInputService:IsKeyDown(Enum.KeyCode.Space) then
--Space is held and touched event fired!
end
end
Note that the above variables would need to be defined such as touchPart, and no ouput will exist unless added. The above code serves to demonstrate how to use UserInputService:IsKeyDown. If you have a question, feel free to ask.
For more detailed code, your use case (what you want to do exactly) would be helpful.
Do u mean if Gui is touched with another Gui?
Huh? He’s asking for help with scripting. Not sure why it’s art design ![]()
Uhh… UserInputService is related to input detection. So I’d recommend it subjected as scripting support. And .Touched is when a part touches another part?
I am asking for scripting support UIS stands for User Input Service its used to detect keyboard and other inputs
The question pertains to two events which require the use of Lua. This is a scripting question. While advice is always appreciated, please take the time to make sure it’s correct and if you are uncertain leave it to the community sages.
To answer the original question. You want to know if two events are occurring at once. You can do this by tracking their state:
- Is one part touching another?
- Is the user currently providing input?
local partsTouching = false
local inputActive = false
local function doEvent()
-- runs when both are active
end
local function tryEvent()
if partsTouching and inputActive then
doEvent()
end
end
part.Touched:Connect(function (hit)
partsTouching = true
tryEvent()
local touchEndListener
touchEndListener = hit.TouchEnded:Connect(function (hit2)
if hit2 == part then
partsTouching = false
touchEndListener:Disconnect()
end
end)
end)
UserInputService.InputBegan:Connect(function (input)
if inputMatchesExpectedInput then
inputActive = true
tryEvent()
end
end)
UserInputService.InputEnded:Connect(function (input)
if inputMatchesExpectedInput then
inputActive = false
end
end)
This code should serve as a good starting point for what you’re trying to do.