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

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

Asked by 5 years ago
Edited by User#24403 5 years ago

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".

```lua 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) ```

```lua 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?

1
Try reading the touch ended documentery on roblox dev. ParentProfanities 28 — 5y
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 starmaq 1290 — 5y

1 answer

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

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
It works! Thank you. TheSweetSim 8 — 5y
Ad

Answer this question