I'm making a script that kills the player ONLY when the color is red. When it is white, I don't want it to kill the player.
Here is what I have so far, it changes the color from white to red, but kills the player no matter which color it is:
01 | while true do |
02 | script.Parent.BrickColor = BrickColor.new(Color 3. new( 255 , 255 , 255 )) |
03 | wait( 3 ) |
04 | script.Parent.BrickColor = BrickColor.new(Color 3. new( 255 , 0 , 0 )) |
05 | function onTouch(part) |
06 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
07 | if (humanoid ~ = nil ) then -- if a humanoid exists, then |
08 | humanoid.Health = 0 -- damage the humanoid |
09 | end |
10 | end |
11 |
12 | script.Parent.Touched:connect(onTouch) |
13 | wait( 3 ) |
14 | end |
Here is the answer!
01 | while true do |
02 | script.Parent.BrickColor = BrickColor.new(Color 3. new( 255 , 255 , 255 )) |
03 | wait( 5 ) |
04 | script.Parent.BrickColor = BrickColor.new(Color 3. new( 255 , 0 , 0 )) |
05 | function onTouch(part) |
06 | if script.Parent.BrickColor = = BrickColor.new(Color 3. new( 255 , 0 , 0 )) then |
07 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
08 | if humanoid ~ = nil then |
09 | humanoid.Health = 0 |
10 | end |
11 | else |
12 | wait() |
13 | end |
14 | end |
15 |
16 | script.Parent.Touched:Connect(onTouch) |
17 | wait( 3 ) |
18 | end |
Something that may be useful to know: when using Color3.new, the highest value that goes in the ()'s is 1 (it won't error if you go above 1), using Color3.fromRGB is where using the integers between 0 and 255 apply. OT: TinyScripter's script is most likely the fix.