#scripting help
1 messages · Page 1 of 1 (latest)
wdym models spawn inside a part
He means every 30s one of the model aka part to spawn
psitd
pairs
local folder = game.folderwtvtf
call it w variable ^
then use pairs to pick a random one
and GetChildren ^
Exactly
Hmmm Alr I’ll test this out
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
Which one do you recommend?
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
if your new, a stationary spot
local children = folder:GetChildren()
local model = children[math.random(#children)]:Clone()
model.Parent = part
you can use while true do loop to spawn each 30s
^ if ur gonna write more code after, use task.spawn
yeah
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
yeah
got ya
yeah, just do a variable that gets the folders children, do a variable for a random number based on the amount of models you got, then use ipairs to get the children from the 2nd variable and do whatever with the v.Name (e.g. make a while true do loop every 30s to do what u want)
And I want this to go own for ever and I don’t want the same model twice in a row to spawn
i think you don't have to do pairs() and ipairs() now
wdym
Okay I understand thanks, Ill try tmw and see if I can figure it out
Yeah I understand that
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
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
aight snm
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