Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script that kills player when the color turns red?

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

2 comments

0

Yep I found your problem. (humanoid ~= nil) should be humanoid ~= nil

0

And some other things, too.

2 answers

✓ Accepted answer

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

1 comment

0

Thank you! It works.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.