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

How to I make the material change?

So I have made a bedframe model and I want to make it change color when the click detector is clicked. I have a RemoteEvent labeled "Event" in my workspace, with a Script inside it. I have a LocalScript in StarterGUI connected to the event. I cannot get it to work and it is getting annoying, any ideas?

Code in the StarterGUI:

local clickdetector = game.Workspace.Bedframe.Pinecone.ClickDetector
clickdetector.MouseClick:Connect(function()
	game.Workspace.Event:FireServer()
end)

Code in the RemoteEvent (Event):

game.Workspace.Event.OnServerEvent:Connect(function()
	game.Workspace.Bedframe.Change.BrickColor="Pine Cone"
end)

3 comments

0

workspace.Bedframe.Change.BrickColor = BrickColor.new("Pine Cone")

0

Updated my answer, hopefully it works now

0

Updated my answer again

1 answer

✓ Accepted answer

You don't need to use remote events with click detectors, just use the .MouseClick event from your detector in your server script like this:

Update: Since game.Workspace.Bedframe.Change is a model, we can't call .BrickColor directly on it, we have to loop through its children and change said property on each of them.

Update2: Change 'waitTime' to the number of seconds you want your parts to stay painted.

local clickdetector = game.Workspace.Bedframe.Pinecone.ClickDetector
local enabled = true
local waitTime = 5
local color = "Pine Cone"
local origColor = "Buttermilk"

clickdetector.MouseClick:Connect(function(player)
	if enabled then
		enabled = false
	    for i, part in pairs(game.Workspace.Bedframe.Change:GetDescendants()) do
	        if part:IsA("BasePart") then
	            part.BrickColor = BrickColor.new(color)
	        end
	    end
		wait(waitTime)
	    for i, part in pairs(game.Workspace.Bedframe.Change:GetDescendants()) do
	        if part:IsA("BasePart") then
	            part.BrickColor = BrickColor.new(origColor)
	        end
	    end
		enabled = true
	end
end)

7 comments

0

Hmm. Still does not work. If this helps, "Change" is a model with the parts I want colored.

0

Oh, if its a model then it doesn't have the BrickColor property. Let me edit my code.

0

No problem! Glad to help :)

0

Actually sorry to pester you once more, but is there anyway I can make it wait and then change back to the original color? (Buttermilk)

0

Thanks again! Thats all I need. Also, never knew you were the creator of a hit game!

0

Oh and if you want to see it being used, join this game: https://www.roblox.com/games/3567225731/Model-Viewing

0

I will gladly give it a look as soon as I can :)

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