the script is a child of the object that being cloned. and the clone function clones the object along with it’s children. and since he use script.parent obviously the script is a child of the object
This advice you gave is still true though. @IAmPinleon you need to make sure that the script is in ServerScriptService and it manages the part without the script being in the part (if it is, we don’t know)
Ok, here is my function (currently, not finished yet):
local secs = 60
repeat
local waitSeconds = math.random(9,20)
local randomAmount = math.random(4,7)
wait(waitSeconds)
for i = 1, randomAmount do
local clonedCrystal = script.Crystal:Clone()
clonedCrystal.Parent = workspace.Crystals
setRandomPosition(clonedCrystal)
end
secs = secs - waitSeconds
until secs <= 0
I’m still using wait() but I want to know how you would do it.
If you don’t mind me asking, is there a better way to wait a small increment of time in what you might call a “good practice” I do agree with using wait() in small increments to be a bad practice but is there any other way to do so in a server script? Sorry if this is random.
You can use os.time(), although i’m not that familiar with it and i prefer tick():
local RunService = game:GetService("RunService")
local cooldown = 20
local lastSpawnedTime = tick()
RunService.Stepped:Connect(function(totalTime, deltaTime) -- these parameters aren't needed but i'm just showing that they exist
if tick() - lastSpawnedTime >= cooldown then
spawnThem()
lastSpawnedTime = tick()
end
end)