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

How do I let "parts" be cframed to basePart?

Asked by 4 years ago

I can't really find a proper way of using this as a question but let me conceptualize;

I wanted to generate 5 parts all with the same sizes although their positions are spreaded out randomly with respect to a basePart

so I did; (the script shown isn't the original but this is a replica of how I did it for the sake of the question)

basePart = script.Parent
rdom = Random.new()

mX, MX = -.5, .5
mY, MY =  -.5, .5
mZ, MZ =  -.5, .5

for i = 1, 5 do

       randomX = rdom:NextNumber(mX, MX)
       randomY = rdom:NextNumber(mY,  MY)
       randomZ = rdom:NextNumber(mZ,  MZ)

       local p = Instance.new("Part", basePart)
       p.Size = Vector3.new(.1, .1, .1)
       p.Position = basePart.Position * CFrame.new(randomX, randomY, randomZ)

end

So what this does is it generates 5 parts and cframes them towards random positions relative to the basePart, but now that they're all placed, I want to CFrame it to the basePart constantly now while still keeping their original positions.

So I'm assuming I have to loop their position to become the basePart's position while still keeping their original right? I did the RenderStepped just for testing and disregarding the reason why I shouldn't use it for minor things like such,

So I grabbed the parts inside the basePart generated,

--inside a runservice function
for i, v in pairs(basePart:GetChildren()) do
      if v:IsA("Part") then 
         v.CFrame = basePart.CFrame:ToObjectSpace(v.CFrame)
end
end

I'm not well educated with CFrames I just know the basics and I really thought this would work but instead, the random generated parts gets thrown away and every individual part's position gets farther and farther away as the loop goes on and on, I'm probably doing it all wrong can anyone enlighten me how to do this efficiently? Thanks!

0
This isn't related to the question or anything, but good job with explaining your question. People don't usually post questions this detailed and long. youtubemasterWOW 2741 — 4y
0
Oh I'll try to help. InspireWithFun 9 — 3y

Answer this question