Good morning everyone!
I know exactly what I need, but I’m not sure how to make it. I need to clone something on the ground within limits of a specific block. I’m not sure where to start.
Thank you so much for any replies,
Ben
Good morning everyone!
I know exactly what I need, but I’m not sure how to make it. I need to clone something on the ground within limits of a specific block. I’m not sure where to start.
Thank you so much for any replies,
Ben
You can clone something like this:
local Part = game.Workspace.Part
local PartClone = Part:Clone()
PartClone.Parent = game.Workspace
You need to manually parent the clone to where you want it to be, because clones are parented to nothing by default.
As for positioning it within a limit of the part, you can use math.random
to generate a random offset. math.random
takes two arguments, the minimum possible number and the maximum possible number, and chooses a random number in between.
For example:
print(math.random(1, 5))
math.random
would generate a random number between 1 and 5 (1, 2, 3, 4, or 5) and print
would print that number.
Now, here’s how you’d position that part around the specific part. This will position it not more than 10 studs away, but you can just change the numbers to increase the limit.
local XOffset = math.random(-10, 10)
local YOffset = math.random(-10, 10)
local ZOffset = math.random(-10, 10)
local SpecificPart = -- the part you want the clone to be positioned around
PartClone.Position = SpecificPart.Position + Vector3.new(XOffset, YOffset, ZOffset)
Sorry about the late reply. I’m trying to get a way for it to spawn in the brick, not outside.
Well that would still work if you use CFrame instead of position and make the offset half of the part’s size so it never spawns out of the part.
So assuming the part is 8 by 8 by 8 in size:
local XOffset = math.random(-4, 4)
local YOffset = math.random(-4, 4)
local ZOffset = math.random(-4, 4)
local SpecificPart = -- the part you want the clone to be positioned around
PartClone.CFrame = SpecificPart.CFrame + Vector3.new(XOffset, YOffset, ZOffset)