How to colour accesories/skintone with click detector?

Hello! i’m creating a RP/hangout game with custom made models that the player gets to customize, but i’m running into a few issues.

First off, i’ve been searching for a skin colour change script that can be activated with a clickdetector, yet i haven’t found one that is compatible for my model. (they do not work well due to my models having extra parts like finger digits and a neck) I’ve tried changing other scripts myself but they do not seem to work.

in short for this small issue id like this code to be alterd to work with a clickdetector in said same part:

bin = script.Parent

function onTouched(part)

part.BrickColor = script.Parent.BrickColor

wait(.3)

end

connection = bin.Touched:connect(onTouched)

Secondly, for my game i plan on making assecories (like clothing items or even face details) for the player to equip and change the colour off, too.

These accesories are made as… well… accesories. I’ve found a way around it but its much harder and might take up alot of space and make the game run badly…

The idea is that the player presses the colour they may desire after equiping the wanted accesory, so that the script may change the colour of the “Handle” (AKA the accesory part) (of said specific assecory, ofcourse!!)


(A picture to clarify!)

A “click to change part colour” script of sorts, but a bit more trickier to code.

Clarification as to where or what to put the script in is appreciated! I’m not very experience with code unfortunately…

Thanks in advance!

2 Likes

Accessories behave slightly differently to parts in that their color(s) is/are not derived from the color of the ‘Handle’ part inside of them. Their color(s) is/are typically controlled by the texture of the mesh inside that ‘Handle’ part. This texture’s color(s) can be modified by changing the mesh’s ‘VertexColor’ property.

https://developer.roblox.com/en-us/api-reference/property/DataModelMesh/VertexColor

2 Likes

The accesory i made (the shirt you see in the example picture) does not posses any textures, actually! It’s simply just a Handle part.

I don’t know if a script may handle it the same way but i have gone and edited the colour of the handle ingame by selecting the avatar and going into the assecory and it seems to be working this way.

In turn id like a script to do this with a clickindicator.

1 Like
local Workspace = workspace
local Part = Workspace.Part --Part that contains a click detector.
local ClickDetector = Part.ClickDetector
local Handle = Workspace.Handle --Part that has its color changed.

ClickDetector.MouseClick:Connect(function(Player) --Player parameter if necessary.
	Handle.BrickColor = BrickColor.new("Hot pink") --Example.
end)

This is an example script but I’ve added comments that should help.

Thank you!

two quick questions before i test this script out:

  1. if im correct this script needs to be placed into a part with a clickdetector, right?

and 2. in the

local Handle = Workspace.Handle --Part that has its color changed.

part of the script, do i need to specify where this handle is placed? i believed you cannot change the Handle name or the accesory will not work… if so how do i “guide” it into an assecory thats inside the player?

I’ve tried the script, but it doesn’t seem to be working on it’s own. i need to find a way to specify for the script to be guided inside the player, then to go inside the right accesory to get to the handle… But i do not know how.

If it’s a handle of an accessory inside the player’s character then you can use the following.

local Workspace = workspace
local Part = Workspace.Part --Part that contains a click detector.
local ClickDetector = Part.ClickDetector

ClickDetector.MouseClick:Connect(function(Player) --Player parameter if necessary.
	local Character = Player.Character --Fetch character from player.
	if not Character then return end
	local Accessory = Character:FindFirstChild("") --Replace empty string with name of accessory.
	if not Accessory then return end
	local Handle = Accessory:FindFirstChild("Handle") --Find handle inside accessory.
	Handle.BrickColor = BrickColor.Random() --Change the handle's color to a random one.
end)

yes! this is what i need!

i will try this out tommorow : )

ive tried it out but it doesn’t seem to work… any ideas on what i may be doing wrong?