nice idea but i believe it might be hard for beginners
Then you shouldn’t teach inefficient practices to beginners, right?
What if the player character is R6? This is not how you should do it. Instead of writing a long chunk of code like this;
A better way to do this is
local char = plr.Character
for i, part in pairs(char:GetChildren()) do -- Loop through every child of character
if part:IsA("BasePart") then -- check if its a basepart (meshpart, union, normal part etc )
part.BrickColor = q -- change color
end
end
oh thanks for improving the code i am doing from what ive learnt so far
i am pretty new so i am doing this till what ive learnt so far
ive changed the code now it looks different
There are some things I’d like to mention out. If you won’t do anything with index, you can replace i
with a _,
. Since you are looping through an array since character:GetChildren()
returns a table of everything which is inside the character, it’s much wiser to use ipairs
.
Also it would be wise to check the data type of q
since the script would error it wasn’t a BrickColor
data type. You should also change q
to something more readable which makes sense.
Here’s how a remastered version of your code would look like:
local character = plr.Character
for _, part in ipairs(char:GetChildren()) do -- Loop through every child of character
if part:IsA("BasePart") and typeof(color) == "brickcolor" and part.BrickColor ~= color then -- check if its a basepart (meshpart, union, normal part etc )
part.BrickColor = color -- change brick color
end
end
Though checking if a brickcolor isn’t the same isn’t necessary but I’d like to have it since it’s my practice to not change something to x if it’s already x.
I was going to make that for a game, this is definitly going to help. Thanks!
nope next part will come soon tho : )
Hmm, don’t know why you’re waiting for the character to load, since the script is firing from a remote, it’d better to check if the character even exists or not.
This is optional.
Can you explain more about this? If you’re talking about the speed, its almost negligible. The array returned by GetChildren() has all numerical indexes so it doesn’t make a difference to use ipairs or pairs.
I didn’t see if it was fired from a remote. It is always good practice to use ipairs
over pairs
when looping through an array. Ipairs
will loop definitely while pairs
will loop indefinitely.
" you can replace i
with a _,
"
Why put it if you don’t want to use it? That’s a bad practice. Same goes for not using self
in a function that uses :
.
In my game i`m using gui ( start customization and leveling changes) for changing Humanoid Description System - its works pretty good with colors.
Waiting for hair\accessories part - for now its works very unstable with my solution - sometimes i cant see actual changes on another player.
I’ll be waiting for it
its coming tommrrow because i havent scripted the hair or any other parts yet lol
ill give a link to part 2 tommrrow
ok folks the part 2 is coming tommorrow
There are much more effecient ways to do this. For example:
Local Script (Put in the same frame as all the color buttons)
local ColorChange = game.ReplicatedStorage:WaitForChild('ColorChange')
local buttonTable = script.Parent:GetChildren()
for index, button in pairs(buttonTable) do
if button:IsA('Button') then
button.MouseButton1Click:Connect(function()
ColorChange:FireServer(button.BackgroundColor3)
end
end
end
Server Script
local ColorChange = game.ReplicatedStorage:WaitForChild('ColorChange')
ColorChange.OnServerEvent:Connect(player, color)
if player.Character then
local character = player.Character
for index, entity in pairs(character:GetChildren()) do
if entity:IsA('BasePart') then
entity.Color3 = color
end
end
end
I’m not 100% if entity.Color3 = color is correct, I wrote it off of memory and in like half a minute. That’s just an example how you can make it MUCH more effecient. Please dont show beginners ineffecient scripting practices. Its great how you are trying to contribute to the continue, but maybe you should begin by learning a little bit more and then trying to teach others about what you learnt. Have a great day!
I do not even believe this is needed. You can take part of the event handler script and make it work solely from the button. Like this:
script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players.LocalPlayer
local q = BrickColor.new("Pastel brown")
for i,v in pairs(char:GetChildren())do
if v:IsA("Part")then
v.BrickColor = q
end
end
end)
I’m sorry about the indentation, I’m on mobile at the moment. This is more efficient, but it is more client-sided. If you would like to make it more protected against exploiters, you can do it the other way.
this tutorial is outdated and it sucks ill release a full version of this (remastered)