Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Jumbuu 110
8 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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

1 answer

Log in to vote
3
Answered by 8 years ago

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)
  
0
This is a good answer. I wouldn't use this method myself but it works. Great job! User#11440 120 — 8y
Ad

Answer this question