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

How do you change a model's color?

Sorry if I'm bad at explaining.

This is my script.

function onTouched(hit)
	script.Parent.Parent.ARGH.Transparency = 1
	script.Parent.Parent.ARGH.CanCollide= true
	wait(7.5)
	script.Parent.Parent.ARGH.Transparency= 1 
	script.Parent.Parent.ARGH.CanCollide= false
end
script.Parent.Touched:connect(onTouched)

After pressing the button, it should change the platform's color. After 7.5 seconds, it goes back to its original color.

I tried something like this to change its color.

script.Parent.Parent.Lite.Lite1.BrickColor = BrickColor.new(Color3.new(1, 1, 1))

However, it didn't work. I couldn't use union, because it says "unsolvable".

Any solutions? (Once again, sorry if it's too hard to understand, I'm really bad at explaining)

2 answers

model = game.Workspace.Model

for i,v in pairs(model:GetChildren())  do -- iterates through the children of the model
if v:IsA("Part") then--if its a part
v.BrickColor = BrickColor.new(Color1.new(1,1,1))--changes color
end
end

1 comment

2

TAB YUR SCRAPT!!!!1111!!111

This version may seem a little long-winded, but basically when it fires, it will:

  1. Set a debounce ( so the funciton only fires once at a time ).

  2. Get a new - random colour for the model change into (You can set this colour to anything you want)).

  3. Scan through the model for Parts.

3.1. Get the part's original colour, and make a copy of it (using a BrickColorValue).

3.2. Change the part's colour.

  1. Wait 7.5 seconds.

  2. Scan through the model for Parts again. 5.1. Change part's colour to original BrickColorValue.

  3. Return Debounce to false.

local model = Workspace.Model -- Change path if neccesarry.

function onTouched(hit)
	--1.
	 if debounce then return end
	debounce = true

	--2.
	local newColour = BrickColor.Random()

	--3.
	for _,part in pairs(model:GetChildren()) do
		if part:IsA("BasePart") or part:IsA("UnionOperation") then
			--3.1.
			local bc = part:FindFirstChild("OriginalBrickColor") or Instance.new("BrickColorValue",part)
			bc.Name = "OriginalBrickColor"
			bc.Value = part.BrickColor

			--3.2.
			part.BrickColor = newColour
		end
	end

	--4
	wait(7.5)

	--5
	for _,part in pairs(model:GetChildren()) do
		if part:IsA("BasePart") or part:IsA("UnionOperation") then
			if part:FindFirstChild("OriginalBrickColor") then -- just incase. =]
				--5.1.
				part.BrickColor = part.OriginalBrickColor.Value
			end
		end
	end

	--6
	debounce = false
end
script.Parent.Touched:connect(onTouched)

1 comment

0

Sorry about the paragraph positioning, something messed up with it, and I can't get it straight ;3

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