The opposite of the "Touched" function

Hello! I am @Enchanted_Tix and I was making something but I needed a function that triggered when the player is NOT touching a brick. See what I mean? If you have suggestions and ways I can do this, comment below and I will try to see if I can script that in my game. If there isn’t, try another way. I don’t know. Please respond at least.

2 Likes

Hi Enchanted_Tix,
I would use the .touchended:connect function to do that
Here’s a script:

local part = script.Parent;
local Players = game:GetService(“Players”);
part.TouchEnded:Connect ( function (hit)
local humanoid = hit.Parent:FindFirstChildOfClass(“Humanoid”);
if humanoid then
local player = Players:GetPlayerFromCharacter(hit.Parent);
–Put your scripting here–
end
end

2 Likes

If you want an event to fire when the player stopped touching the brick, you can use TouchEnded. If you just want to check if the player is touching the part, you can use :GetTouchingParts(). GetTouching returns a table of all the parts that are currently touching it. You can use a for loop and an if statement to check if one of the parts in the table is a descendant of your character.

Okay. Random question being thrown at you, @iNoobe_yt, but how do I locate a part if something is in it? Like if I create a part(s), and there is a ObjectValue called “Water”. How will I locate parts using the value?

That’s not a very good way of finding parts since it’ll be hard to locate it.

You could use recursion to check every single object in the game and check to see if “Water” is a descendant of it.

How do I use recursion? And is there another way to locate a part using something?

Recursion is when you call a function inside of the function itself. There are many ways to locate a part, when something specific happens to the part, you can store it in a variable so you won’t need to look for it.