Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with a part's surface?

Asked by 9 years ago

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

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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).

1
What's the brackets for in line 3? kevinnight45 550 — 9y
0
To adjust each surface property. For example, for the first loop, it would take "Back" in the array and reference it to "surface" in line 3. Since all surfaces have the common word "Surface", he cleverly added (or concatenate) the string value that's from the array to "Surface". "BackSurface" would result, and the property of 'Part' for the apparent BackSurface would be set to "Smooth" Redbullusa 1580 — 9y
0
The brackets act just like `.` except that you can use variables inside, instead of just names (e.g., using `part["Name"]` vs `part.Name`) BlueTaslem 18071 — 9y
Ad

Answer this question