I want this script to run as long a player is touching it. Why doesn't it run at all?
1 | repeat |
2 | script.Parent.BrickColor = BrickColor.new( "Institutional white" ) |
3 | wait( 1 ) |
4 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
5 | wait( 1 ) |
6 | until script.Parent.TouchEnded |
TouchEnded is an event, not a bool value. You can make it a bool value like this:
01 | local partTouching = nil --The current part touching touch part. |
02 | local touchPart = script.Parent --The brick to be used with this script. |
03 |
04 | touchPart.Touched:connect( function (part) |
05 | partTouching = part --Set the variable to the current touching part. |
06 | repeat |
07 | script.Parent.BrickColor = BrickColor.new( "Institutional white" ) |
08 | wait( 1 ) |
09 | script.Parent.BrickColor = BrickColor.new( "Really black" ) |
10 | wait( 1 ) |
11 | until not partTouching |
12 | end ) |
13 | touchPart.TouchEnded:connect( function (part) --When the touch stops, this event is emitted. |
14 | if part = = partTouching then |
15 | partTouching = nil --This part is no longer touching. |
16 | end |
17 | end ) |
If you have any questions or issues, feel free to comment below.