- What do you want to achieve?
I am making a Plates of Fate style of game and want any Parts I spawn onto a plate to be welded onto it. So if the plate grows in size or starts spinning or just moves in any way at all, the Part will move with it.
-
What is the issue?
I can’t figure out how to do it correctly, the Parts are either 40-80 studs in the air OR if I do manage to get it to move with it, the Part is perfectly inside the plate. -
What solutions have you tried so far?
Combinations of different calculations in the Welds, using WeldConstraints to try to achieve the same effect.
This is the code I currently have right now. (It gets called from an external script as it is a ModuleScript)
local function getRandomPlateMidRound()
platesFolder = workspace["Play Area"]:WaitForChild("Plates")
local plates = platesFolder:GetChildren()
if #plates == nil or #plates == 0 then
return false
end
local randomPlate = plates[math.random(1, #plates)]
return randomPlate
end
local function randomOnSurface(part)
local x,y,z = part.Size.X,part.Size.Y,part.Size.Z
local xPosition = math.random(-x,x)
local zPosition = math.random(-z,z)
local middle = part.CFrame + part.CFrame.UpVector*(y/2)
local rx,ry,rz = middle:ToOrientation()
return CFrame.new(middle*Vector3.new(xPosition/2,0,zPosition/2))*CFrame.Angles(rx,ry,rz)
end
...
PlateEvents.SpawningPartTest = function(timer, targetCount)
local eventDesc = "PART SPAWN TEST"
countdownTimer(timer, eventDesc, targetCount)
for i=1, targetCount, 1 do
local randomPlate = getRandomPlateMidRound()
if randomPlate ~= false then
local part = Instance.new("Part")
part.CFrame = CFrame.new(0,0,0)
part.Color = Color3.new(0.337255, 1, 0.0941176)
local weld = Instance.new("Weld")
weld.Part0 = part
weld.Part1 = randomPlate
weld.C0 = (randomOnSurface(randomPlate))
weld.C1 = (randomOnSurface(randomPlate))
weld.C0 = weld.C0 * CFrame.new(0, randomPlate.Size.Y, 0)
weld.Parent = part
part.Parent = randomPlate
highlightSelectedPlate(randomPlate)
playPopSound(randomPlate)
task.wait(0.35)
end
end
task.wait(1)
end