How do i fix this? (trying to do multiple cframes at once)

Im Trying to make a Model that resembles multiple individual zombies move forward along with their legs swinging.

Here is the script.

--Spawn horde
function SleepingHorde()
	local horde = game.ServerStorage.SleepingHorde
	local hordecopy = horde:Clone()
	hordecopy.Parent = game.Workspace
end

-- zombies wake up
function AwakenHorde()
	local sleepinghorde = game.Workspace.SleepingHorde
	local awakenhorde = game.ServerStorage.AwakenHorde
	local hordecopy = awakenhorde:Clone()
	sleepinghorde:Destroy()
	hordecopy.Parent = game.Workspace
	--they move
	local place = CFrame.new(40,100.376,0.01)
	local move = Vector3.new(1,0,0)
	for count = 1, 200 do
		wait(0.07)
		place += move
		hordecopy:SetPrimaryPartCFrame(place)
	end
end

-- makes the legs animate
function legs()
	wait(0.5)
	local part = workspace.AwakenHorde.Legs:GetChildren()
	while true do
		for count = 1, 30 do
			local rotation = part.CFrame * CFrame.Angles(0, 0, math.rad(1))
			wait(0.05)
			part.CFrame = rotation
		end
		for count = 1, 30 do
			local rotation = part.CFrame * CFrame.Angles(0, 0, math.rad(-1))
			wait(0.05)
			part.CFrame = rotation
		end
	end
end


SleepingHorde()
wait(5)
legscorountine = coroutine.create(legs)
coroutine.resume(legscorountine)
AwakenHorde()

When i run it the zombies wake up fine and they start moving forward… BUT none of their legs move.
the legs() function works fine when used on a single part but not on a bunch of parts I just cant solve this. Any tips on what i could to to fix this? thanks.

1 Like

Edit: Nvm good job putting the code in the appropriate formatting

Yep, that’s the problem it’s probably to do with the referencing to the legs CFrame where the script doesn’t know which specific “part” you are moving.

local part = workspace.AwakenHorde.Legs:GetChildren()
while true do
for count = 1, 30 do
local rotation = part.CFrame * CFrame.Angles(0, 0, math.rad(1))
wait(0.05)
part.CFrame = rotation

To solve this you would need to make sure to reference each individual leg part correctly, then use a for loop to change each of those individual leg parts. Or you can group the legs together in a model and change a single primary part CFrame.

Sorry for not including a picture earlier. But as you can see I have many zombies that im trying to move all with this one script. Wouldnt looping through all of the legs make them take turn one at a time? im trying to make them start all at once.

Well yes, but usually when working with cframe the computer(server or client) will usually loop through all the legs real fast. Otherwise you can just group up the legs with a primary part in a model and go from there.

Edit: or you can weld constraint all the legs to one singular leg, this will make one cframe transformation apply to this one leg apply to the rest