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 6 years ago
Edited 6 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:

while true do
script.Parent.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
wait(3)
script.Parent.BrickColor = BrickColor.new(Color3.new(255, 0, 0))
    function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid ~= nil) then   -- if a humanoid exists, then
        humanoid.Health = 0 -- damage the humanoid
    end
end

script.Parent.Touched:connect(onTouch)
wait(3)
end

0
Yep I found your problem. (humanoid ~= nil) should be humanoid ~= nil TinyScripter 70 — 6y
0
And some other things, too. TinyScripter 70 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Here is the answer!

while true do
script.Parent.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
wait(5)
script.Parent.BrickColor = BrickColor.new(Color3.new(255, 0, 0))
    function onTouch(part)
    if script.Parent.BrickColor == BrickColor.new(Color3.new(255, 0, 0)) then
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if humanoid ~= nil then 
        humanoid.Health = 0
    end
    else
        wait()
    end
    end

script.Parent.Touched:Connect(onTouch)
wait(3)
end
0
Thank you! It works. ElectronicMask 4 — 6y
Ad
Log in to vote
0
Answered by 6 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