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).
I want to achieve that whilst the character is on a part, that part changes color.
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)
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?
Here is what it looks like (I later changed the code a bit, including color etc... but the fundamental problem remains)