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

How do I change the color of a part when I step on a different part?

Hello, I'm trying to make a part change color when a different part is stepped on. Let's say, when "Part A" is being stepped on "Part B" will change it's color from Ghost grey to Bright yellow. But if you step off "Part A", "Part B" will change back to Ghost Grey. I'm pretty new to scripting, so this is probably very easy. I have no code for "Part A". Here is the code from "Part B".

game.Workspace.Function.OnInvoke = function()

end

script.Parent.Touched:Connect(function()

script.Parent.BrickColor = BrickColor.new("Bright yellow")

end)

  

script.Parent.TouchEnded:Connect(function()

script.Parent.BrickColor = BrickColor.new("Ghost grey")

end)
script.Parent.Touched:Connect(function()

script.Parent.Material = ("Neon")

end)

  

script.Parent.TouchEnded:Connect(function()

script.Parent.Material = ("SmoothPlastic")

end)

Could someone please help me?

2 comments

1

Try reading the touch ended documentery on roblox dev.

0

isnt this working? it seemms fine? all though why do 2 events? while you can just change the material and the colour with 1 event at the same time so just put the material changing with the color changing in the touched and untouched events

1 answer

✓ Accepted answer

I've created a little script that can help you in this case, Place it inside Part A:

script.Parent.touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
	    workspace.PartB.BrickColor = BrickColor.new("Bright yellow")
    end
end)

script.Parent.touchEnded:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
	    workspace.PartB.BrickColor = BrickColor.new("Ghost grey")
    end
end)

1 comment

1

It works! Thank you.

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