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)
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)
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.
--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
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.
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)