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

How do I move the created part?

Asked by 5 years ago

I am trying to make a random drop loot. How do I move the created part to the random location?

Do I even need a dropper? How do I just randomly spawn it?


local ReplicatedStorage = game.ReplicatedStorage local LOOT = ReplicatedStorage:WaitForChild('LOOT') local DropperPart = workspace:WaitForChild('DropperPart') local xPos = {500,-540} local yPos = {200,250} local zPos = {482,-652} while wait(math.random(1,10)) do local m = LOOT:Clone() local x = math.random(xPos[1], xPos[2]) local y = math.random(yPos[1], yPos[2]) local z = math.random(zPos[1], zPos[2]) m.Parent = DropperPart --[[how to move it]] m:MoveTo(Vector3.new(x,y,z)) game:GetService('Debris'):AddItem(m,90) end
0
i don't see any problems with the script Questofmagicfarts 55 — 5y
0
but you shouldn't use while wait() use while true do wait(math.random(1,10)) end Questofmagicfarts 55 — 5y
0
he can use while wait() do, except as a legendary programmer once said, its a bad practice to use that since it works mainly on roblox. greatneil80 2647 — 5y
0
Don't arrays start at [0]? mixgingengerina10 223 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

So if I were to create a dropper, id allow roblox to handle the physics and i'd just spawn the part and use coroutines to end the part.

something like this:

local loot = game.ReplicatedStorage:WaitForChild("LOOT")
local dropperP = workspace.DropperPart
while true do wait(math.random(1,10))
spawn(function()
local m = loot:Clone()
m.Parent = workspace
local x = math.random(-540,500)
local y = math.random(200,250)
local z = math.random(-652,482)
if m.ClassName == "Model" then
    m:SetPrimaryPartCFrame(CFrame.new(x,y,z))
    for _, v in pairs(m:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Anchored = false
        end
    end
elseif m.ClassName == "Part" then
    m.Position = Vector3.new(x,y,z)
    m.Anchored = false
end
wait(90)
m:Destroy()
end)
end

This should work, if your crate is a model then go to properties and Set your primary part cframe to an object inside your model, if it is a part then you dont need to worry, I havent tested this but it should work, im just disabling collisions.

If this works, then id greatly appreciate it if you accept the answer

0
Thank you. Asher0606 36 — 5y
0
No problem! greatneil80 2647 — 5y
Ad

Answer this question