You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A “Builder” NPC that walks around randomly and places randomly-generated parts.
What is the issue? Include screenshots / videos if possible!
It doesnt place parts, but theres no error.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
None, yes, found nothing.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local placeNow=script.Parent.placeNow
function place()
local b1=Instance.new("Part")
Instance.new("Part")
b1.Color=BrickColor.random()
b1.Parent=workspace
b1.Name="Brick"
script.Shape.Value=math.random(1,4)
if script.Shape.Value==1 then
b1.Shape="Block"
end
if script.Shape.Value==2 then
b1.Shape="Ball"
end
if script.Shape.Value==3 then
b1.Shape="Cylinder"
end
if script.Shape.Value==4 then
b1.Shape="Truss"
end
b1.Position=script.Parent.Head.Place.Position
end
while true do
placeNow.Event:Connect(place)
wait(math.random(1,5))
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Unfortunately there were many issues that I could spot with your script, so it was more convenient for me to rewrite it for you:
local partType = Enum.PartType:GetEnumItems() -- Gets an array of each different part type
local function placePart() -- Local functions are preferable over global functions, unless you're coding a module
local part = Instance.new("Part") -- For some reason you were creating 2 parts in the original script
part.BrickColor = BrickColor.random() -- part.Color needs a Color3 value, not a BrickColor, so use part.BrickColor...
-- ...if you want to use BrickColor.random()
part.Name = "Brick"
part.Position = Vector3.new(0, 8, 0) -- This is for debugging, in-order to make sure the parts are being created
part.Shape = partType[math.random(#partType)] -- Sets the part's shape to a random type
part.Parent = workspace -- Make sure you set an Instance's parent after you're done setting its properties!
end
while true do
placePart() -- Call the placePart function whenever you want to generate a new part
task.wait(math.random(5)) -- Using math.random with only one value will automatically set 1 as the minimum
end -- Using task.wait is preferable over wait, since wait is limited to run at 30fps and isn't able to directly talk to the task sheduler
I wrote as many detailed comments as I could think of in-order to help explain some of the issues in the original script, and how the new script works
I’d recommend keeping them since it makes code much easier to read and debug, but here’s a version without spaces:
local partType=Enum.PartType:GetEnumItems()--Gets an array of each different part type
local function placePart()--Local functions are preferable over global functions, unless you're coding a module
local part=Instance.new("Part")--For some reason you were creating 2 parts in the original script
part.BrickColor=BrickColor.random()--part.Color needs a Color3 value, not a BrickColor, so use part.BrickColor...
--...if you want to use BrickColor.random()
part.Name="Brick"
part.Position=Vector3.new(0,8,0)--This is for debugging, in-order to make sure the parts are being created
part.Shape=partType[math.random(#partType)]--Sets the part's shape to a random type
part.Parent=workspace--Make sure you set an Instance's parent after you're done setting its properties!
end
while true do
placePart()--Call the placePart function whenever you want to generate a new part
task.wait(math.random(5))--Using math.random with only one value will automatically set 1 as the minimum
end--Using task.wait is preferable over wait, since wait is limited to run at 30fps and isn't able to directly talk to the task sheduler
IIRC there are plugins available that can handle removing spaces for you, although do be sure to check that they’re from a reputable source before installing them
Vector3 doesn’t have a built-in random function, so you’ll need to do this instead (line 9 is where the size is being set):
local partType=Enum.PartType:GetEnumItems()--Gets an array of each different part type
local function placePart()--Local functions are preferable over global functions, unless you're coding a module
local part=Instance.new("Part")--For some reason you were creating 2 parts in the original script
part.BrickColor=BrickColor.random()--part.Color needs a Color3 value, not a BrickColor, so use part.BrickColor...
--...if you want to use BrickColor.random()
part.Name="Brick"
part.Position=Vector3.new(0,8,0)--This is for debugging, in-order to make sure the parts are being created
part.Size=Vector3.new(math.random(5,12),math.random(3,10),math.random(2))
part.Shape=partType[math.random(#partType)]--Sets the part's shape to a random type
part.Parent=workspace--Make sure you set an Instance's parent after you're done setting its properties!
end
while true do
placePart()--Call the placePart function whenever you want to generate a new part
task.wait(math.random(5))--Using math.random with only one value will automatically set 1 as the minimum
end--Using task.wait is preferable over wait, since wait is limited to run at 30fps and isn't able to directly talk to the task sheduler