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

What's wrong with this script?

Asked by 10 years ago
function makeBrick()
    Block = Instance.new("Part")
    Block.Name = "RoundBlock"
    Block.Shape = "Ball"
    Block.Size = Vector3.new(4,4,4)
    Block.Position = Part.Position + 4
    Block.BrickColor = BrickColor.new("Bright red")
    Block.Parent = game.Workspace
end

while true do
    wait(10)
    makeBrick()
end

--the brick doesn't spawn

2 answers

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

On line 6 of that code block, you are trying to access Part.Position, which doesn't exist in that context.

Remove the reference, or make sure that Part is a valid reference to a BasePart Instance.

1
Alright, but is there a way to make the new part spawn 4 studs above the Part's position? (I got it to spawn, all i need is this answered now) LegoDude9630 15 — 10y
0
Yes, you just have to tell the script what "Part" is a reference to. At the top of the script, put 'local Part = Workspace.Part' without the apostrophes, and change 'Workspace.Part' to the hierarchy for the Part you are referring to. adark 5487 — 10y
Ad
Log in to vote
0
Answered by
ked2000 15
10 years ago

Like what adark said, Part does not exist, you must use the instance you created which is Block.

Also, you have to use Vector3 and add two Vector3's together. The end result is this.

function makeBrick()
    Block = Instance.new("Part")
    Block.Name = "RoundBlock"
    Block.Shape = "Ball"
    Block.Size = Vector3.new(4,4,4)
    Block.Position = Vector3.new(Block.Position.X, Block.Position.Y, Block.Position.Z) + Vector3.new(0, 4, 0)
    Block.BrickColor = BrickColor.new("Bright red")
    Block.Parent = game.Workspace
end

while true do
    wait(10)
    makeBrick()
end
0
The default for Position is Vector3.new(), so accessing Block.Position is useless. As well, you can just use Block.Position directly, instead of constructing it that way. adark 5487 — 10y
0
They both have the same effect. I just really don't pay attention to efficiency. ked2000 15 — 10y

Answer this question