- What do you want to achieve?
- Pick a random part and a random spawn.
- Clone the part, and make its position the random spawn’s.
- Remove the spawn from the available spawn pool.
- Re-fill the pool once empty.
-
What is the issue?
Every method I’ve tried so far, mostly revolving around removing the children from the table, has failed. I’ve contacted dozens of people to no avail. -
What solutions have you tried so far?
Methods such as table.remove, creating a new folder for approved spawns, creating a value to check if the spawn is being used or not, among many others.
Module Script
local eggModule = {}
-- Services
local replicatedStr = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
-- Folders
local eggFolder = replicatedStr:WaitForChild("eggFolder")
local spawnFolder = workspace.gameFolder.Interactive:WaitForChild("eggSpawns")
local spawnedEggFolder = workspace.gameFolder.Interactive:WaitForChild("eggClones")
-- Settings
local Settings = {
bodyPosTween = Vector3.new(0, 1, 0)
}
-- Module
function createEggTween(eggCopy)
local bodyPos = Instance.new("BodyPosition")
bodyPos.Position = eggCopy.Position
bodyPos.MaxForce = Vector3.new(40000, 40000, 40000)
bodyPos.Parent = eggCopy
local posTween = tweenService:Create(bodyPos, TweenInfo.new(0.8, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
Position = bodyPos.Position + Settings.bodyPosTween
})
posTween:Play()
print("bodyPos")
end
function eggModule:spawnEgg(Rarity)
local spawnTable = spawnFolder:WaitForChild(Rarity):GetChildren()
local randomSpawn = spawnTable[math.random(1, #spawnTable)]
if #randomSpawn < 1 then
local eggTable = eggFolder:WaitForChild(Rarity):GetChildren()
local randomEgg = eggTable[math.random(1, #eggTable)]
local eggCopy = randomEgg:Clone()
eggCopy.Parent = randomSpawn
eggCopy.Position = randomSpawn.Position
createEggTween(eggCopy)
end
end
return eggModule
ServerScript (parent of Module, all in ServerScriptService)
-- Module
local eggModule = require(script.eggModule)
-- Folders
local gameFolder = workspace:WaitForChild("gameFolder")
-- Settings
local eggTypes = {
'Basic',
'Rare',
'Special'
}
-- Loop
while wait(5) do
local chosenType = eggTypes[math.random(1, #eggTypes)]
local eggCount = gameFolder.Interactive.eggClones:GetChildren()
if #eggCount < 5 then
eggModule:spawnEgg(chosenType)
end
end
I’ve included the full script in case the issue lies elsewhere.
Thank you in advance and stay safe!
Marco