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

How would I loop through 700+ dummies in groups/chunks?

local Animations = {"1717926935","1717928321","2374934310","2374957118","2374969328","2374970669"}
AnimationControl = script.AnimationControl


local Run = 250
local Count = -1
game:GetService("RunService").Heartbeat:Connect(function()
    Count = (Count + 1)%Run
    if Count ~= 0 then
        return
    end
    if game.Workspace:FindFirstChild("Spectators") ~= nil then
		for i, v in pairs(game.Workspace.Spectators.Backside:GetDescendants()) do	
		if v:IsA("AnimationController") then
	AnimationControl.AnimationId = "http://www.roblox.com/asset?id="..Animations[math.random(1, #Animations)]
	local PlayCelebration = v:LoadAnimation(AnimationControl)
	PlayCelebration:Play()	
			end
			end
end
end)

So I've made this piece of code that goes through "game.Workspace.Spectators.Backside" and gets all its descendants, looking for an animationcontroller to play an animation selected randomly from the table. I'm currently looping through 700+ animationcontrollers, since I have 700+ dummies I want to play an animation for. With my current code, the animations are played in sync for all 700+ dummies at the same time. However, I would much rather have the Heartbeat loop play a random animation, at random times, for random dummies, instead of everything being synced and played at the same time.

Right now, this is being ran in a local script, and because it's going through 700+ dummies, it's actually giving some FPS performance issues. That's another reason why I would like to iterate through the descendants in chunks/groups rather than all of them at the same time. I'm unsure of how to achieve this though, which is why I've decided to come on here and ask.

So to summarize my questions:

- How would I be able to loop through all the dummies and play the animation in random chunks/groups rather than all 700+ dummies at once?

- How would I be able to do this at random times, instead of everything being done at the same time?

Here's an example of the dummies:

Thank you very much!

Regards, Shurikanz

1 answer

✓ Accepted answer

If you want the dummies to be handled in groups , then you separate them into folders, and then have a script handling each folder.

If you want them to be handled individually, you should put a script into each dummy.

Concerning lag, it's ROBLOX. There are going to be some compromises on performance when you have over 700 dummies performing animations simultaneously. I would recommend seriously considering if this is necessary - maybe have a 'master' dummy that you clone in whenever you need it?

For example, when somebody opens a door, you can simply

local clone = game:GetService('ServerStorage')["Master Dummy"]:Clone()
clone.Position = Vector3.new(player.Position.X + 5, 2, player.Position.Z - 5)
clone.Parent = workspace

3 comments

0

I could do folders and assign a script to each folder, but I would much rather have one master script control everything in chunks, instead of all 700+ at once. Maybe load animations into 100 for every loop but not sure how to do this. All the 700+ dummies are used at an arena as the audience, so they need to be there from the start. There's a screenshot link in my post above :)

0

I understand the want to use a master script, but this isn't always the most efficient way. Maybe you could create one script in ServerStorage or ReplicatedStorage that is set to disabled, and have the master script clone it into a folder of dummies in the workspace, and re-enable it (effectively running it), and have it remove itself once it's finished.

1

I figured out a way to do it with the help of Ultraw, but I'll accept your answer anyway. Thanks for trying to help. Your approach would have been a good alternative as well :D

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