New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Help with table?

Asked by
FiredDusk 1465 Moderation Voter
4 years ago

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)

0
I would suggest using a for loop btw raspyjessie 117 — 4y
0
Come on PreyStar, don't be like that. You know mine is correct Im_Kritz 334 — 4y
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. Perci1 4944 — 4y

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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.

Ad

Answer this question