Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I move the created part?

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


4 comments

0

i don't see any problems with the script

0

but you shouldn't use while wait() use while true do wait(math.random(1,10)) end

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.

0

Don't arrays start at [0]?

1 answer

✓ Accepted answer

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

2 comments

0

Thank you.

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.