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 make a part change colour when it comes in contact with another part?

I don't even know how to script, but I am making a game based in a factory, and I need the products to change colour when they come in contact with a machine, can someone help?

2 comments

0

Knowing absolutley nothing about scripting and working on a game is total useleness, learn before, you wouldn't want people to script everything you come across do you? This is a basic thing, i'm sure any super basic scripter would know how to

0

starmacc is correct

1 answer

Here's a simple script that makes the script's parent (Must be a BasePart) change color when it touches a specific part.

local Color_To_Change_To = BrickColor.new("New Yeller") -- The BrickColor to change to.
local Color_Changer = workspace.YourPartHere -- When this script's parent (Must be a BasePart) touches this part, it'll change color.

script.Parent.Touched:Connect(function(Touched_Part) -- When this script's parent (Must be a BasePart) comes in contact with another part, this chunk of code will run.
if Touched_Part == Color_Changer then -- See if the part touched by this script's parent (Must be a BasePart) is the Color_Changer part or not. If so, continues the code. Otherwise, the code will stop running from there.
script.Parent.BrickColor = Color_To_Change_To -- Change this script's parent's (Must be a BasePart) BrickColor property to Color_To_Change_To.
end -- Ending the If logic gate.
end) -- Ending the chunk of code.

Hopefully this helped!

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