Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what do people use to stop a touched event from running unless activated?

i am really lost on this and some guidance would be appreciated. this isn t a request

1 answer

✓ Accepted answer

By using TouchEnded.

Let's say you want to print "(Player Name) touching (part name)" while a player is touching a part, and when they stop touching it, print "(Player Name) stopped touching (Part Name)".

First of all, let's start with defining the variables;

local part=workspace.Part --this is the part that will be touched (sounds weird), really the only variable we need.

Now, we need to check when the part is being touched, and if it's a player;

local part=workspace.Part

part.Touched:connect(function(touched) --anonymous function, touched is what is touching the part
  if touched.Parent:FindFirstChild("Humanoid") then --if humanoid is found in touched parent, then it's a player 
  end
end)

So, we have that part done. So far, the script will check if something touched it, and whether it was a player or not. Now for the printing part;

local part=workspace.Part

part.Touched:connect(function(touched) --anonymous function, touched is what is touching the part
  if touched.Parent:FindFirstChild("Humanoid") then
      player=touched.Parent --this is the players character
      print(player.Name..' touched '..part.Name) --This will print, in my case 'SimplyRekt touched Part'
  end
end)

So that part of the script is done. Let's go to the touch ended part.

TouchEnded works basically the same exact way. TouchEnded fires when something stops touching, rather than starts. Here's the rest of the script that you'd add to the first one;

part.TouchEnded:connect(function(touched)
  if touched.Parent:FindFirstChild("Humanoid") then
      player=touched.Parent
      print(player.Name..' stoped touching '..part.Name)
  end
end)

1 comment

0

This is a good answer. I wouldn't use this method myself but it works. Great job!

This discussion is preserved as it was. New answers, comments, and votes are closed.