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

Is there a way to simplify this color changing script?

I have a script within a gui that allows the player to change the color of their hair/clothes/etc to whatever they choose. The problem is it can get pretty messy. I have a bunch of similar scripts for each color and it's really building up. Is there an easier way to call certain parts from a morph's head and chest parts?

playerman = script.Parent.Parent.Parent.Parent.Parent.Character
function changecolor()
-- headparts
playerman.HeadPart.HairTop.BrickColor = BrickColor.new("Persimmon")
playerman.HeadPart.Hair.BrickColor = BrickColor.new("Persimmon")
playerman.HeadPart.EyebrowsMad.BrickColor = BrickColor.new("Really red")
playerman.HeadPart.EyebrowsNeutral.BrickColor = BrickColor.new("Really red")
playerman.HeadPart.HairBack.BrickColor = BrickColor.new("Persimmon")
-- chest
playerman.Chest.Cap.BrickColor = BrickColor.new("Salmon")
playerman.Chest.Shirt.BrickColor = BrickColor.new("Crimson")
playerman.Chest.Hat.BrickColor = BrickColor.new("Really red")
wait()
end

script.Parent.MouseButton1Click:connect(changecolor)

3 comments

0

Well, I would recommend to have variables for the "playerman.HeadPart" sections to prevent repetitive retypings, and perhaps (maybe(?) create variables for the separate colours, or a table, but I don't recommend that option, as that'll take a lot more work, same with the making variables for the colours, as I can't 100% confirm that that can solve your problem/ question. ;c

0

I have an idea of what method to use but I don't know the proper termonolgy of what it's called. Either tables or instances or..? Something like that. I tried researching them but I don't know how to apply them to my scripts :(

0

If I had to guess, are you referring to Arrays? But more specifically, Dictionaries? http://wiki.roblox.com/index.php?title=Table#Dictionaries

3 answers

I'm guessing you are putting that script inside each color button that they choose? I guess that since you are using script.Parent.MouseButton1Click, i would recommend using a ModuleScript and then just requiring it and calling it inside that script so you don't have to change every. single, script. it's a little more work but it's worth the effort.

This could help a little:

Make a variable that reffers to playerman.HeadPart. Then make an array that contains all parts that are supposed to change their brickcolor to, for example "Really red". Repeat for every color. Then use a for loop to go through every part inside each array, and change its color.

http://wiki.roblox.com/index.php?title=Generic_for

You should look on addictedroblox1414's answer aswell. It's a pretty good idea. Do what he says, and just pass some arguments to the function that will tell it what colors it should switch to.

not that i know of, there might be a way but i cant find one.

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