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

how to move multiple pats at once? :GetChildren()

local spiders = script.Parent:WaitForChild("Spiders"):GetChildren()

for i, v in pairs(spiders) do
	if v:IsA("MeshPart") then	
		for i= 1, 80 do
            spiders.CFrame = spiders.CFrame * CFrame.new(0,0,-0.3)
			wait()
             end
        end
end

Workspace.Model.Script:6: invalid argument #1 (CFrame expected, got nil)

I want a script that will make multiple spiders run forward, but I don't want to make variables for 20+ spiders.

2 answers

✓ Accepted answer

For loop runs one time with each child inside of the parent that is defined.

You could use a ModuleScript and create a function to reduce the use while having a script in each spider and just call the function.

ModuleScript - Named "MoveModule" in "ReplicatedStorage"

local moveModule = {}

function moveModule:MoveSpider(spider)
	for num = 1,80 do
		game:GetService("RunService").Stepped:Wait()
		spider.CFrame = spider.CFrame * CFrame.new(0,0,-0.3)
	end
end

return moveModule

ServerScript - Named "MoveScript" in each spider

local moveModule = require(game:GetService("ReplicatedStorage"):WaitForChild("MoveModule")

moveModule:MoveSpider(script.Parent)

This somewhat reduces memory use as it's not being written multiple times, but called multiple times.

Hope this helped! Feel free to select this as an answer if this helped you!

you can use a for k,v get descendants on the spiders.

local spiders = script.Parent:WaitForChild("Spiders")

  for k,v in pairs(spiders:GetDescendants()) do
        if v:IsA("MeshPart") then
          for i= 1, 80 do
            v.CFrame = v.CFrame * CFrame.new(0,0,-0.3)
               wait()
             end
     end
end
  • TELL ME IF THIS WORKS!
local spider = script.Parent


for i= 1, 80 do
      spider.CFrame = spider.CFrame * CFrame.new(0,0,-0.3)
               wait()
end
  • PUT THIS SCRIPT IN EVERY SPIDER

8 comments

0

edited and put in your script.

0

they move once at a time, I need them all of them to move at the same time

0

you could always try to make it one part, let me think i'll see what i can do though.

0

@14dark14 i have attempted to make a script, i haven't tested it, make a primary part centered with the spiders, name it PrimaryPart, Anchor it and put this in the model (second choice edit)

0

wont work if I made them into 1 part because the spiders run different directions, If you wont be able to come up something I will have to make separate script for each spider

0

i found a way, check the edit, put that script in every spider.

0

yeah I know, thats what I didnt want to do, I know I could do that, but I want to keep stuff optimized.

0

you could do one script that goes for all spiders, for example, local spider1 = script.Parent["Spider1"] in the model and then keep doing that with for i = 1,80 for each or one for i = 1,80 with all cframes in

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