On line 10-19 there is a table that should loop around turning each surface of "Part" smooth but it won't,why? How would I fix this problem?
Player = game.Players.LocalPlayer Character = game.Players.LocalPlayer.Character Tool = script.Parent ---------------------------- function CreatePart(CFPosition) local Part = Instance.new("Part",game.Workspace) Part.FormFactor = "Custom" Part.Size = Vector3.new(1,0.2,1) Part.CFrame = CFPosition local Surfaces ={ Part.BackSurface, Part.BottomSurface, Part.FrontSurface, Part.LeftSurface, Part.RightSurface, Part.TopSurface} for i,v in pairs (Surfaces)do print(v) v = "Smooth" end return Part end function RandomNumbers(Num1,Num2) local RandomNumbers = { math.random(Num1,Num2), math.random(Num1,Num2), math.random(Num1,Num2)} return RandomNumbers end ---------------------------- Tool.Equipped:connect(function(Mouse) Mouse.Button1Down:connect(function() for Index = 1,5 do local PartPosition = CFrame.new(Mouse.Hit.p)*CFrame.new(0,1,0) local RandomNumbers = RandomNumbers(1,10) local RandomizedPosition = PartPosition*CFrame.new(RandomNumbers[1],RandomNumbers[2],RandomNumbers[3])--Scatters part at random positions in diffrent axis local Parts = CreatePart(RandomizedPosition) Parts.Name = "Part"..Index end end) end)
P.s I got no errors in the output
Assigning to v
just assigns to v
It doesn't change Part
or it surfaces, any more than the following changes 5
:
five = 5 five = 7
You have to explicitly modify the object that you want to change. That could look something like this:
local Surfaces = {"Back", "Bottom", "Top", "Left", "Right", "Front"} for _, surface in pairs(Surfaces) do Part[ surface .. "Surface"] = "Smooth" end
The square brackets Part[ ]
is just like using Part.property
, except that you can use expressions (variables) inside, rather than just some particular name.
As an example, Part.Name
is actually doing Part["Name"]
.
If we wanted a property but didn't know which one, we could do
property = "Name" print( Part[property] )
Note that Part.property
would not work, because that asks for the property named "property" (which Part
doesn't have).