Hello, I am having a problem with my script. My script is supposed to take a block and move it to a random spot within a certain bricks size and then throw the block outward. However, this works fine if the spawner is placed on the ground. Everything will spawn where it needs to be, but when I put the spawner in the air, the blocks are spawned in the air and then not even close to the spawner where I need it. Can somebody help explain why this is happening and how to fix it?
wait(math.random(1,4))
local debris = game:GetService("Debris")
local rock = script:WaitForChild("ROCK")
local ran = Random.new(tick())
rock.Parent = nil
function getPosition()
local halfSize = script.Parent.Size * .5
local objPos = Vector3.new(ran:NextNumber(-halfSize.X, halfSize.X), script.Parent.CFrame.Y, ran:NextNumber(-halfSize.Z, halfSize.Z))
return objPos
end
function makeBLOCK()
local cl = rock:Clone()
local location = getPosition()
cl.Hot.Anchored = false
cl.Hot.Velocity = Vector3.new(math.random(-20,20), math.random(50,110), math.random(-20,20)) -- Push the blocks up and put them in different directions using velocit
cl.Parent = script.Parent
cl:SetPrimaryPartCFrame(CFrame.new(script.Parent.CFrame * location)
debris:AddItem(cl,math.random(6,12))
end
while true do
wait(math.random(2,7))
--wait(1)
for i = 1, math.random(1,6) do
makeBLOCK()
end
end