#scripting help

1 messages · Page 1 of 1 (latest)

topaz moon
#

so i have 9 models in a folder which i want every 30 seconds one of those models spawn in a part randomly, and ive tried a lot of things, but it aint working, please help a guy out

limber tusk
#

wdym models spawn inside a part

raven solstice
limber tusk
#

so it chooses a model at a random time

#

and puts it at a part

fading gazelle
#

pairs

#

local folder = game.folderwtvtf

#

call it w variable ^

#

then use pairs to pick a random one

#

and GetChildren ^

topaz moon
topaz moon
fading gazelle
#

are they already in position?

#

or does it go to a random pos or what

#

@topaz moon

#

quick question

#

by models in a folder

#

do you mean multiple parts inside of a model, and multiple models inside of a folder type shi?

#

like this

topaz moon
#

Do they have to be in replicated storage

fading gazelle
#

nah just put them there cus why not

#

they can be on the map

#

however

topaz moon
fading gazelle
#

if u put them in RS you can pre-position them, and simply change the parent of a part to workspace and back to RS

fading gazelle
pure quail
#

you can use while true do loop to spawn each 30s

fading gazelle
#

^ if ur gonna write more code after, use task.spawn

topaz moon
#

I think I understand, just to be clear, what I want here is this folder with 7 models and I want to randomly have one of those models to spawn a certain position ones every like 30 seconds or smth

fading gazelle
topaz moon
pure quail
pure quail
#

oh nvm

topaz moon
fading gazelle
#

like this

#

top one should be ur folder

#

not replicated storage

topaz moon
#

Yeah I understand that

fading gazelle
#

well

#

if urs is in there then yeah

#

or wait ill add more comments rq

#
local folder = game.ReplicatedStorage.ModelsFolder  -- your folder

local function printRandomModelContents() -- function iyw to use more later
    local models = folder:GetChildren() -- get all models in folder

    local randomModel = models[math.random(1, #models)] -- 1, #models gives you a random number between 1 and the amount of models in the folder

    print("Random Model: "..randomModel.Name) -- prints random model name, change these prints to what you wanna do though
    print("Items in model: ")

    for _, item in ipairs(randomModel:GetChildren()) do -- picks a random model
        print(" -", item.Name) -- prints all the items inside the random model
    end
end

while true do
    printRandomModelContents() -- loops it and calls the function
    task.wait(1) -- set it to 30 iyw that
end
#

theres more comments

#

easier than me explaining it over here

topaz moon
#

Okay thank you so much, I was struggling badly I think I understand now, I’ll try it out tmw and tell u how it goes

fading gazelle
#

aight snm

topaz moon
# fading gazelle ```lua local folder = game.ReplicatedStorage.ModelsFolder -- your folder local...

local spawnPart = workspace:WaitForChild("SnowBallSpawn") -- the single spawn part
local modelsFolder = workspace:WaitForChild("SnowBallModels") -- folder containing 9 models
local SPAWN_DELAY = 30 -- seconds

local function spawnRandomModel()
local models = modelsFolder:GetChildren()
if #models == 0 then
warn("No models found in SnowBallModels!")
return
end

-- pick a random model
local randomModel = models[math.random(1, #models)]

-- clone it
local clone = randomModel:Clone()

-- If the model has no PrimaryPart, assign one automatically
if not clone.PrimaryPart then
    -- try setting the first BasePart as primary
    for _, part in ipairs(clone:GetDescendants()) do
        if part:IsA("BasePart") then
            clone.PrimaryPart = part
            break
        end
    end
end

-- still no PrimaryPart? can't position the model
if not clone.PrimaryPart then
    warn("Model " .. randomModel.Name .. " has no BasePart to position!")
    return
end

-- position the model on the spawn part
clone:SetPrimaryPartCFrame(spawnPart.CFrame)

-- parent to workspace
clone.Parent = workspace

end

-- loop every X seconds
while true do
spawnRandomModel()
task.wait(SPAWN_DELAY)
end

#

yeah it dosnt work still

#

it would be highly appricated if someone could join a call with me and i can show exactly how i want it to be so its 100% clear

#

tried doing it like yours aswell