Body Colour Script not working!

So I have made a Body Colour GUI that when a button is clicked, the button’s RGB colour goes to a Color3Value and then triggers this script.

My problem is that whenever I do it, the character’s body colour goes to 0, 0, 0 (The Color3Value’s default value). This isn’t a timing issue because if I click it after the first time, it still goes to black.

This is my Script (In StartCharScripts):

local char = script.Parent
local event = game.ReplicatedStorage.Customize.Events.BodyColour

local valueDefiner = game.ReplicatedStorage.Customize.Values.ColourValue


event.OnServerEvent:Connect(function()
	
	local colour = valueDefiner.Value
	
	
	for i, part in pairs(char:GetChildren()) do
		if part:IsA("BasePart") then
			part.BrickColor = BrickColor.new(colour)
		end
	end	
end)

Hi!

If you’re using RGB you should do it like this:

part.Color = Color3.fromRGB(ColourChosen)
1 Like

I’ll try this out right now, thank you!

Update: Still receiving the same problem. The Color3Value is still functional in changing and there were no errors.

Please print out what color the color3Value(ChosenColor) is, the problem seems to be there. :slight_smile:

It seems to be printing 0, 0, 0 regardless of the fact that the actual value is 199, 172, 120 so you’re right, that is the problem.

How do you save the value? Maybe I can help you out there. :slight_smile:

The script below is responsible for changing the value to the colour:

local GUI = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent

local player = game.Players.LocalPlayer

local char = player.Character

local event = game.ReplicatedStorage.Customize.Events.BodyColour

local button = script.Parent

local colour = Color3.fromRGB(199, 172, 120)

local colourValue = game.ReplicatedStorage.Customize.Values.ColourValue

button.MouseButton1Click:Connect(function()

colourValue.Value = colour

event:FireServer()

end)

And after that is done, is the ColourValue (199, 172, 120) in ReplicatedStorage?

Yes, this is it after I click the button:

Screen Shot 2022-05-03 at 6.40.39 PM

It’s because your trying to assign a Color3 value to a BrickColor value. You could do…

BrickColor.new(Color3.new(r, g, b))

We’ve transfered him over to using Color3 value instead of BrickColor. :slight_smile:

1 Like

Printing the Color3 value also gives me the same result.

So this prints 0,0,0?

local char = script.Parent
local event = game.ReplicatedStorage.Customize.Events.BodyColour

local valueDefiner = game.ReplicatedStorage.Customize.Values.ColourValue


event.OnServerEvent:Connect(function()
	
	print(valueDefiner.Value)
	
	for i, part in pairs(char:GetChildren()) do
		if part:IsA("BasePart") then
			part.Color = Color3.fromRGB(valueDefiner.Value)
-- If that doesn't work, try this: part.Color = Color3.new(valueDefiner.Value)
-- If all fails try this: part.Color = valueDefiner.Value
		end
	end	
end)

I cannot remember which approach is the correct. :slight_smile:

--In my own game I have used 
Part.Color = Color.fromRGB(ColorTable[R],ColorTable[G],ColorTable[B])
-- But that is due to me saving the color in their datastore

All 3 did not work for me. It also prints 0, 0, 0 in all of them as well.

Wait a second. Ofc it will print 0,0,0. You’re changing the colourValue from the client, not the server. If you wish to send the new colour to the server, you could send it through the RemoteEvent. :slight_smile:

Edit: Just make sure to check on the server, that the color they’ve sent is a valid color, they have access to changing themself into. (or what they change color of)

Alright. So what your saying is that when the button is clicked on the client it changes the value on the server then grabs the value on the server and gives it to the player?

Edit: Basically Client → Server
. . . . . . . . . . . . . . . V ---- After ----> Server

What I am saying is, you should send the colorvalue in here:

--ClientScript
event:FireServer(colour)

And now for the server:

event.OnServerEvent:Connect(function(player,colour) -- First argument here will always be the player that sent the remote, all arguments comes after that like normal. So if player sent argument1 from client as "colour", then it will come up as argument2 on the server.
	if typeof(colour) == "Color3" then -- Checks that it is a Color3 value, and not anything random sent by the client
		-- Do colorchanging here
	end
end)

You don’t even need the ReplicatedStorage colour value, if you only use it for the simple case of storing it temporarily, between client/server. (Because that is not really how it works)

Okay, I’m gonna work on that I’ll get back to you in 10ish minutes.

I’VE DONE IT!! What I did was make the LocalScript only fire the event, then add this ServerScript in the button:


local button = script.Parent
local event = game.ReplicatedStorage.Customize.Events.BodyColour

local valueDefiner = game.ReplicatedStorage.Customize.Values.ColourValue


event.OnServerEvent:Connect(function()
	
	valueDefiner.Value = button.BackgroundColor3
	
end)