How can I make one script's job apply to all the parts in a model instead of having to paste the script in each part seperatly?

Ah, well then just the top one :confused:

local Model = script.Parent
for i,v in pairs(Model:GetChildren()) do -- iterates through every part
  if v:IsA("BasePart") and v["Name"] == "Step" then
   v.Touched:Connect(function(Hit) -- hit is the part, so you would do,
       Hit.BrickColor = BrickColor.random() -- sets the color
       end)
   end
end

and I did remember to group the “steps” and put the script in the Model

Can you take a photo of your stairs model in the explorer so I can understand what’s in the model.

No, it’s because his script is in the model, but it had the Touched function ran on it anyways making it error.

Not possible, there is an if statement checking if the Instance is a BasePart

Yeah, but in the script he was using, it was after the touched function. Having it check after it fired the touched event.

1 Like

Screenshot (97)

1 Like

Yeah i fixed it above, your hit was lowercase so just copy the script again and it will work.

do you want it to change for 1 player or everyone?

It’s for whoever steps on it in the game

aaaaaand nope, still nothing. The touchinterest appears in the “step” but no color change

local Model = script.Parent
for i,v in pairs(Model:GetChildren()) do
    if v:IsA("BasePart") and v["Name"] == "Step" then
        v.Touched:Connect(function()
            v.BrickColor = BrickColor.random() 
        end)
    end
end
2 Likes

Oh my good lord it worked! Thank you so much!

And, I’m really really sorry to ask this, is there a way for the color to change back to one color after a certain time period?

local Model = script.Parent
for i,v in pairs(Model:GetChildren()) do
    if v:IsA("BasePart") and v["Name"] == "Step" then
        v.Touched:Connect(function()
        	local OldColor = v.BrickColor -- Save the color before random
            v.BrickColor = BrickColor.random() 
            wait(5) -- Wait 5 seconds
            v.BrickColor = OldColor
        end)
    end
end

Is oldColor where I put the color name of what I want it to revert to?

The variable OldColor, will keep track of the color that it was before it was ever randomized.
But yes, you can put a specific colour in

1 Like

would I write 163, 162, 165 (the RGB value of the color), or Medium Stone Grey in replacement of OldColor

local Model = script.Parent
for i,v in pairs(Model:GetChildren()) do
    if v:IsA("BasePart") and v["Name"] == "Step" then
        v.Touched:Connect(function()
        	local OldColor = BrickColor.new(Color3.new(163, 162, 165)) -- Save the color before random
            v.BrickColor = BrickColor.random() 
            wait(5) -- Wait 5 seconds
            v.BrickColor = OldColor
        end)
    end
end