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

Changing Brick colors when another object touches it?

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

1 answer

Both of these scripts both work, but you can choose. This code below only activates if it detects a Humanoid.

script.Parent.Touched:Connect(function(plr)
	local Humanoid = plr.Parent:FindFirstChildWhichIsA("Humanoid")
	if Humanoid then
		script.Parent.BrickColor = BrickColor.Random()
	end
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.

script.Parent.Touched:Connect(function()
		script.Parent.BrickColor = BrickColor.Random()
end)

Hope this helps!

REQUEST

script.Parent.Touched:Connect(function(Touched)
	if Touched.Parent.Name == "Blah" then -- In blah put your part name.
		script.Parent.BrickColor = BrickColor.Random()
	end
end)
-- Put a script in a part and create a tool or whatever you're using to change the color.
-- Put the tool name exactly as what Blah or what you put there says. 
-- Put a part in the tool named Handle.

3 comments

0

Just saying, what if the part of the character that touched it was an accessory? You would need plr.Parent.Parent, right? But you know, whatever works. :)

0

You would need to use FindFirstAncestorWhichIsA("Model") and then check if that model is a character of a player via GetPlayerFromCharacter (in case if there are any models that are touching the part) however I may be overcomplicating things...

0

I'll put your request in my answer.

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