Color not working

game.Players.PlayerAdded:Connect(function(Player)

	local partsFolder = workspace:WaitForChild("Parts")
	local colorButtons = Player.PlayerGui:WaitForChild("ScreenGui").Frame
	local colorchosen = Color3.fromRGB(0, 0, 0)



	local function changePartColor(part)
		print("Changing color of part:", part.Name, "to color:", colorchosen)
		part.Color = Color3.new(colorchosen)
		print("New color of part:", part.Name, "is:", part.Color)
	end

	for _, part in ipairs(partsFolder:GetChildren()) do
		if part:IsA("BasePart") then
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = part


			clickDetector.MouseClick:Connect(function()
				changePartColor(part)
			
			end)
		end
	end

	for i, Button in pairs(colorButtons:GetChildren()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function()
				colorchosen = Button.Value.Value
			end)
		end
		
	end		

end)

this should work and it’ll find the screengui

also this is wrong because i just tested it out and I was able to detect clicks

well, its not working but it is finding the screen gui because there are no errors

game.Players.PlayerAdded:Connect(function(Player)

	local partsFolder = workspace:WaitForChild("Parts")
	local colorButtons = Player.PlayerGui:WaitForChild("ScreenGui").Frame
	local colorchosen = Color3.fromRGB(0, 0, 0)



	local function changePartColor(part, colorpicked)
		print("Changing color of part:", part.Name, "to color:", colorpicked)
		part.Color = Color3.new(colorpicked)
		print("New color of part:", part.Name, "is:", part.Color)
	end



	for i, Button in pairs(colorButtons:GetChildren()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function()
				colorchosen = Button.Value.Value
			end)
		end
		
	end		

	for _, part in ipairs(partsFolder:GetChildren()) do
		if part:IsA("BasePart") then
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = part


			clickDetector.MouseClick:Connect(function()
				changePartColor(part, colorchosen)
			
			end)
		end
	end

end)	

how about this?

nope
///////////////////////////////////////

not even an error
//////////////

also i removed the print thing in the changecolor function and just replaced it with print(“the color was changed”)

ok so what I think you should do instead is to create a stringvalue in every player in players that holds what value they selected from the menu. then you can use this as a reference point to decide what colour they will use instead of a variable if that makes sense.

makes sense, do i just create a stringvalue like this?

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
-- code to add string here
end)

yeah like that and whenever they select from the menu, change the value according to what they clicked

ok im home now, ill see if that works

also, i will put the color in leaderstats for debugging (maybe ill keep it)

1 Like
local players = game:GetService("Players")
	players.PlayerAdded:Connect(function(player)
		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
		
		local Color = Instance.new("StringValue")
		Color.Parent = leaderstats
		Color.Name = "Color"
	end)

done, now how do i change the value to what they clicked

game.Players.PlayerAdded:Connect(function(Player)

	local partsFolder = workspace:WaitForChild("Parts")
	local colorButtons = Player.PlayerGui:WaitForChild("ScreenGui").Frame
	local colorchosen = Color3.fromRGB(0, 0, 0)

	local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
		
		local Color = Instance.new("StringValue")
		Color.Parent = leaderstats
		Color.Name = "Color"


	local function changePartColor(part, colorpicked)
		print("Changing color of part:", part.Name, "to color:", colorpicked)
		part.Color = Color3.new( [replace with dictionary name] [colorpicked])
		print("New color of part:", part.Name, "is:", part.Color)
	end



	for i, Button in pairs(colorButtons:GetChildren()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function()
				Player.Color.Value = Button.Value.Value
			end)
		end
		
	end		

	for _, part in ipairs(partsFolder:GetChildren()) do
		if part:IsA("BasePart") then
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = part


			clickDetector.MouseClick:Connect(function()
				changePartColor(part, Player.Color.Value)
			
			end)
		end
	end

end)

not done yet, you now have to create a dictonary that has the hex code associated to its colour for example:

Purple = #FF0789

doesnt work, says unknown global “player”

capitalise player and it should work

19:55:55.913 Unable to assign property Value. string expected, got Color3 - Server - Script:27

hold on not done yet

oh ok
////////////////////////////////////////

game.Players.PlayerAdded:Connect(function(Player)

	local partsFolder = workspace:WaitForChild("Parts")
	local colorButtons = Player.PlayerGui:WaitForChild("ScreenGui").Frame

	Colors = { "Red" = "#FF0000", "Yellow" = "#FFE600", "Green" = "#45DB00", "Light Blue" = "#00FFE1", "Blue" = "#008CFF", "Pink" = "#FF00FF", "Purple" = "#BF00FF", "White" = "#FFFFFF", "Black" = "#000000" }

	local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
		
		local Color = Instance.new("StringValue")
		Color.Parent = leaderstats
		Color.Name = "Color"


	local function changePartColor(part, colorpicked)
		print("Changing color of part:", part.Name, "to color:", colorpicked)
		part.Color = Color3.new(Colors[colorpicked])
		print("New color of part:", part.Name, "is:", part.Color)
	end



	for i, Button in pairs(colorButtons:GetChildren()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function()
				Player.Color.Value = Button.Name
			end)
		end
		
	end		

	for _, part in ipairs(partsFolder:GetChildren()) do
		if part:IsA("BasePart") then
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = part


			clickDetector.MouseClick:Connect(function()
				changePartColor(part, Player.Color.Value)
			
			end)
		end
	end

end)

this should work but i have a question, is each button’s value in hexadecimal?