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
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