title: Touched function Roblox Studio
body: <p>I am coding an obby on Roblox Studio. In this obby, I have parts that the character jumps on (the parts are roughly 10 by 10 studs).</p>
  
  <p>I want to achieve that whilst the character is on a part, that part changes color.</p>
  
  <pre class="lang-lua prettyprint-override"><code>local platform = script.parent
  
  local function changeColor(part)
     local humanoid = part.Parent:FindFirstChild(‘Humanoid’)
     if humanoid then 
     part.BrickColor = BrickColor.new(‘Bright red’)
     end
  end
  
  local function restoreColor(part)
     local humanoid = part.Parent:FindFirstChild(‘Humanoid’)
     if humanoid then 
     part.BrickColor = BrickColor.new(‘Grey’)
     end
  end
  
  platform.Touched:connect(changeColor)
  platform.TouchEnded:connect(restoreColor)
  </code></pre>
  
  <p>The problem with this, is that as the character walks on the part, the part changes from grey to red and back with each step. I want the part to remain red for the duration of the player being on it. So I want the function to check whether the player has walked on it in the last say .5 seconds, to give the player time to walk without reverting the color. Is this the right approach, and if so how would I go about it. Is it possible to override the touched function?</p>
  
  <p>Here is what it looks like (I later changed the code a bit, including color etc... but the fundamental problem remains)</p>
  
  <p><a href="https://i.stack.imgur.com/DJkrl.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DJkrl.gif" alt="enter image description here"></a></p>