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

How to detect if a part is a certain color?

Asked by 10 years ago

I have a brick, and I want to make an "if then" function..

For example, if the color is Really Blue, then make the part's transparency .5. I'm not sure how to make a script detect the color... any help?

EDIT: Why doesn't this work?

Brick = script.Parent AnotherBrick = game.Workspace.TP

if game.Workspace.Screen.brickcolor.Name == "Bright green" then Brick.Touched:connect(function(part) if part.Parent.Humanoid then -- * if part.Parent.Humanoid.Health > 0 then part.Parent:MoveTo(AnotherBrick.Position) end end end)

2 answers

Log in to vote
1
Answered by 10 years ago
if game.Workspace.Part.brickColor.Name == "Really blue"
    then
    game.Workspace.Part.Transparency = 0.5
end
Ad
Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

This line of code will take the children of a certain location and apply the transformation if the colour of the child is Really blue:

local children = game.Workspace.Model:GetChildren() -- the game.Workspace.Model should be changed to the place you want to search for the part at.

for i = 1, #children do
    if children[i]:IsA("BasePart") == true and children[i].BrickColor == "Really Blue" then
        children[i].Transparency = 0.5
    end
end
0
Thank you, but read my edited description.. I need help with the second part now DrCylonide 158 — 10y
0
It's hard to read the way you laid it out, but I spotted a couple errors. Send me a Roblox message with the script and I'll try to help you further! BlackJPI 2658 — 10y

Answer this question