I want to figure out how to make a script that has a brick change color when it is touched by another object. I know how to do it when a character touches it, but I'm not sure what I need to change to have it happen for another object.
script.Parent.Touched:connect(function() script.Parent.BrickColor = BrickColor.new("Cyan") wait(2) script.Parent.BrickColor = BrickColor.new("Medium stone grey")
end)
This is what I have for changing it when a character touches it
Both of these scripts both work, but you can choose. This code below only activates if it detects a Humanoid.
1 | script.Parent.Touched:Connect( function (plr) |
2 | local Humanoid = plr.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
3 | if Humanoid then |
4 | script.Parent.BrickColor = BrickColor.Random() |
5 | end |
6 | end ) |
However this script is slightly different, instead of just the Humanoid being able to touch it anything can. Like a baseplate for an example.
1 | script.Parent.Touched:Connect( function () |
2 | script.Parent.BrickColor = BrickColor.Random() |
3 | end ) |
Hope this helps!
REQUEST
1 | script.Parent.Touched:Connect( function (Touched) |
2 | if Touched.Parent.Name = = "Blah" then -- In blah put your part name. |
3 | script.Parent.BrickColor = BrickColor.Random() |
4 | end |
5 | end ) |
6 | -- Put a script in a part and create a tool or whatever you're using to change the color. |
7 | -- Put the tool name exactly as what Blah or what you put there says. |
8 | -- Put a part in the tool named Handle. |