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

Changing Brick colors when another object touches it?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.
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. :) User#25069 0 — 5y
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... Mr_Unlucky 1085 — 5y
0
I'll put your request in my answer. iiBuilder_Boy 27 — 5y
Ad

Answer this question