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

How do I detect if a part has a certain brickcolor?

I have this very long script, it works kind of, but I want to learn how to detect the color without a touch event. Anyone that know how to do that?

This script should detect a certain color and then all the other parts that has other colors should disappear.

local platform = script.Parent
platform.Transparency = 1

while true do
local randomValue = math.random(1, 7)
print(randomValue)
if randomValue == 1 then
	print("Purple")
elseif randomValue == 2 then
	print("Pink")
elseif randomValue == 3 then
	print("White")
elseif randomValue == 4 then
	print("Yellow")
elseif randomValue == 5 then
	print("Green")
elseif randomValue == 6 then
	print("Blue")
elseif randomValue == 7 then
	print("Red")
end
wait(5)

platform.Touched:Connect(function(hit)
	print(hit)
	if randomValue == 1 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Electric blue" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Lilac" then
			--hit.Transparency = 1
			--hit.CanCollide = true
		end
		
	end
	
	if randomValue == 2 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Electric blue" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Sunrise" then
			--hit.Transparency = 1
			--hit.CanCollide = true
			elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
	if randomValue == 3 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Electric blue" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Pearl" then
			--hit.Transparency = 1
			--hit.CanCollide = true
			elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
	if randomValue == 4 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Electric blue" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Daisy orange" then
		--	hit.Transparency = 1
			--hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
			elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
	if randomValue == 5 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Electric blue" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Moss" then
		--	hit.Transparency = 1
		--	hit.CanCollide = true
			elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
	if randomValue == 6 then
		if hit.BrickColor.Name == "Terra Cotta" then
			hit.Transparency = 1
			hit.CanCollide = true
		--elseif hit.BrickColor.Name == "Electric blue" then
		--	hit.Transparency = 1
			--hit.CanCollide = true
			elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
	if randomValue == 7 then
		--if hit.BrickColor.Name == "Terra Cotta" then
			--hit.Transparency = 1
			--hit.CanCollide = true
			if hit.BrickColor.Name == "Electric blue" then
				hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Moss" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Daisy orange" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Pearl" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Sunrise" then
			hit.Transparency = 1
			hit.CanCollide = true
		elseif hit.BrickColor.Name == "Lilac" then
			hit.Transparency = 1
			hit.CanCollide = true
		end

	end
	
wait(5)
hit.Transparency = 0
hit.CanCollide = false
	
end)
end

Thanks, Xsodar

1 comment

0

All parts in a model to be clear

1 answer

If you want to check part without touching it you could use Changed event it should look like this

platform.Changed:Connect(function()
--put anything you want this will also will be fired only once the part changes(color size ext.)
end)

and if you want to delete you part you can use Destroy()

platform.Changed:Connect(function()
platform:Destroy()
end)

I hope i helped you.

1 comment

0

What I wanted to do was to find if a certain part has for example the color blue. I want see if for example of all 50 parts in the model have a certain color. If 20 of them has the color blue all the other ones disappear. Do you understand me more now?

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