How to make a dictionary of the color of the body parts of a player?

So here’s some code I have

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)

	wait(5)

	local char = plr.Character

	for i,Child in pairs (char:GetChildren()) do
		if Child:IsA("MeshPart") then

			Child.Color = Color3.fromRGB(112, 69, 255)

			Child.Material = 'ForceField'

		end
	end


	for i,Child in pairs (char:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA('MeshPart')

			ChildA.Color = Color3.fromRGB(112, 69, 255)

			ChildA.Material = 'ForceField'

			--	char.Head.face.Transparency = 1

		end
	end

	wait(5)
	
	-- do thing
	
end)

after the wait(5) I want to give the player their colors back and also their proper material, my problem is how to grab the color values that they had before they were changed?

Hello,

You could create a variable before they are changed on line 6, which would store the color value before it is changed.

You could then retrieve this after the wit on line 34.

I hope this helped!

2 Likes

this does explain it better, but my problem is how to do the whole “store the color” code part :I?, doesnt need to be the whole code done, I just want some hints or whatever to at least start somewhere

Players.PlayerAdded:Connect(function(plr)

	wait(5)

	local char = plr.Character
	
	local SavedColorTable = {}

	for i,Child in pairs (char:GetChildren()) do
		if Child:IsA("MeshPart") then
			
			SavedColorTable[Child.Name] = Child.Color
			
			Child.Color = Color3.fromRGB(112, 69, 255)

			Child.Material = 'ForceField'

		end
	end


	for i,Child in pairs (char:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA('MeshPart')

			ChildA.Color = Color3.fromRGB(112, 69, 255)

			ChildA.Material = 'ForceField'

			--	char.Head.face.Transparency = 1

		end
	end

	wait(5)

	-- do thing

end)

Printing SavedColorTable will return a table of the limb’s colors.

huh strange, I didnt get anything …?

Print it from inside of the function.

ah yes, it printed with the values!, how can I now grab those values and use one by one ?

SavedColorTable[“InsertBodyPartHere”] would give you the color of that body part.

you could probably do something along the lines of:

for bodypart, color in pairs (SavedColorTable) do
    player.Character[bodypart].Color = color
end
1 Like

this helped a lot thank you!, going to post the finished script now!

1 Like

thanks everybody who replied, the script is finally done! and pretty easy to mess around with too!

local Players = game:GetService("Players")

local function onCharacterAdded(character)

	local SavedColorTable = {}

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then

			SavedColorTable[Child.Name] = Child.Color
			print(SavedColorTable)
			
		end
	end
	
	wait(0.01)
	
	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then
			
			Child.Color = Color3.fromRGB(112, 69, 255)
			

			Child.Material = 'ForceField'

		end
	end
	


	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA('MeshPart')
			

			ChildA.Color = Color3.fromRGB(112, 69, 255)
			

			ChildA.Material = 'ForceField'

		end
	end

	wait(3) -- time until it returns to normal

	for bodypart, color in pairs (SavedColorTable) do
		character[bodypart].Color = color
	end

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then

			Child.Material = 'Plastic'

		end
	end
	
	
	
	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA('MeshPart')

			ChildA.Color = Color3.fromRGB(255, 255, 255)

			ChildA.Material = 'Plastic'

		end
	end
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

have fun with it!
example of it in action:

https://gyazo.com/6315ec4ec975e2a7f52a84b3936d70d2

2 Likes