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

What's wrong with this script?

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

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.

2 comments

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)

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.

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

2 comments

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.

0

They both have the same effect. I just really don't pay attention to efficiency.

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