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

Script that kills player when the color turns red?

Asked by 7 years ago
Edited 7 years ago

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:

01while true do
02script.Parent.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
03wait(3)
04script.Parent.BrickColor = BrickColor.new(Color3.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
10end
11 
12script.Parent.Touched:connect(onTouch)
13wait(3)
14end
0
Yep I found your problem. (humanoid ~= nil) should be humanoid ~= nil TinyScripter 70 — 7y
0
And some other things, too. TinyScripter 70 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Here is the answer!

01while true do
02script.Parent.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
03wait(5)
04script.Parent.BrickColor = BrickColor.new(Color3.new(255, 0, 0))
05    function onTouch(part)
06    if script.Parent.BrickColor == BrickColor.new(Color3.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 
16script.Parent.Touched:Connect(onTouch)
17wait(3)
18end
0
Thank you! It works. ElectronicMask 4 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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.

Answer this question