Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with table?

I am trying to set all players character parts to a certain size. Its not working.

player = game.Players.LocalPlayer

CharParts = {"Right Arm", "Right Leg", "Left Arm", "Left Leg", "Head", "Torso"}

player.Character.CharParts[1].Size = Vector3.new(0.4, 0.8, 0.4)
player.Character.CharParts[2].Size = Vector3.new(0.4, 0.8, 0.4)
player.Character.CharParts[3].Size = Vector3.new(0.4, 0.8, 0.4)
player.Character.CharParts[4].Size = Vector3.new(0.4, 0.8, 0.4)

3 comments

0

I would suggest using a for loop btw

0

Come on PreyStar, don't be like that. You know mine is correct

0

The innate problem with changing your body part's size is the welds. It's not as simple as you may think. However, the correct format for your lines are: player.Character[CharParts[1]].Size. Since CharParts[1] is a string, we have to use brackets.

1 answer

✓ Accepted answer

This is how you for loop it

EDIT: Admins want me to explain my code.

Instead of changing each and every single part on the player one by one. It's more efficient to use a For Loop to change them for you instead. Also, it is more convenient to just loop with a player:GetChildren() and change for parts.

for _,v in pairs(player:GetChildren()) do
if not v:IsA('Part') then return end
-- Code
end

But doing that means any part that gets grouped in the player will also be affected. Therefore, putting the names of the parts in a table is a fine method.

local CharParts = {"Right Arm", "Right Leg", "Left Arm", "Left Leg", "Head", "Torso"}

for i = 1, #CharParts do
-- Code
end

More importantly, you need to define the part using :FindFirstChild() and to change the parts' size below Vector3.new(1,1,1) , you got to change their FormFactor to Custom. Then you can change it to Vector3.new(.35,.35,.35) and above.

local Part = player.Character:FindFirstChild(CharParts[i])
Part.FormFactor = "Custom"

This is the final tested code:

local player = game.Players.LocalPlayer
local CharParts = {"Right Arm", "Right Leg", "Left Arm", "Left Leg", "Head", "Torso"}

for i = 1, #CharParts do
local Part = player.Character:FindFirstChild(CharParts[i])
Part.FormFactor = "Custom"
Part.Size = Vector3.new(0.4, 0.8, 0.4)
end

There you go I think I explained every single part of the final code.

This discussion is preserved as it was. New answers, comments, and votes are closed.