Color Gui Character [SOLVED]

Im trying to achieve ColorCharacter/Morphs in Gui

Video Short clip

https://gyazo.com/b39e673d3c1421f6de9fd3f8c740ad3a/preview

Script is here to get this work.

Script or LocalScript

script.Parent.MouseButton1Click:Connect(function()

local CC = game.Workspace:GetChildren()

CC.Arm1.Part.BrickColor = BrickColor.new(“Navy blue”)

CC.Arm2.Part.BrickColor = BrickColor.new(“Navy blue”)

CC.Chest.Part.BrickColor = BrickColor.new(“Navy blue”)

CC.Leg1.Part.BrickColor = BrickColor.new(“Navy blue”)

CC.Leg2.Part.BrickColor = BrickColor.new(“Navy blue”)

end)

Issue found??

21:29:33.609 - Players.Joshua7ninjaX.PlayerGui.CharacterColor.Frame.TextButton.LocalScript:3: attempt to index field ‘Arm1’ (a nil value)

GetChildren returns an array of children, it does not return a dictionary.
What’s the use of GetChildren here?
You can just do workspace.Arm1.Part etc.

Arm1 is the model and Part is Part

no like what @return_end1 said, you are using GetChildren that gets an array of stuff inside of workspace, why do you need to do that if you are trying to find certain parts?

Article for help: Instance | Documentation - Roblox Creator Hub

(btw your video clip is not working for me)

I am pretty sure you also need the server to change the body colors for your model.

My slightly mistake, it is game.Players.GetChildren() not workspace, i mean inside Workspace player(Characters)

Hello! As @return_end1 explained, the script errors because CC is a table, not an object. Since you also have doubts on when to use local or regular scripts, you could do that this way:

Local script

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer() -- you can also add arguments in there, such as the color!
end)

You have to define event, which should be a RemoteEvent object located, for instance, inside game.ReplicatedStorage. When used correctly, these can make your game safer against exploits. See more info here.

Normal script

event.OnServerEvent:Connect(function()
	local CC = workspace -- Your actual bug!!!
	local color = BrickColor.new(“Navy blue”) -- Tip: memorizing a variable is usually less expensive than creating tons of new BrickColor values
	CC.Arm1.Part.BrickColor = color
	CC.Arm2.Part.BrickColor = color
	CC.Chest.Part.BrickColor = color
	CC.Leg1.Part.BrickColor = color
	CC.Leg2.Part.BrickColor = color
end)

Likewise, you will have to reference the event here too.

3 Likes

if you are trying to find the player then from @mishajones has provided, in your event add:

event.OnServerEvent:Connect(function(player)
    local character = player.Character -- this is the character model in workspace
    -- code here
end)