Is there a better way / cleaner way to do this?

Is there a way to make this better or cleaner? I feel like there’s a more efficient way to do this but I can’t figure out how I’d go about it.

I tried putting it all in one loop, but the countdown wouldn’t be the same for everyone if it is looping through multiple people

for _, plr in Runners do
    if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
        plr.Character.HumanoidRootPart.CFrame = Teleports.Course_Spawns:GetChildren()[math.random(1, #Teleports.Course_Spawns:GetChildren())].CFrame
    end
end

for _, plr in Runners do
    if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
        plr.Character.Humanoid.WalkSpeed = 0
    end
end

-- // countdown
wait(3)

for _, plr in Runners do
    if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
        plr.Character.Humanoid.WalkSpeed = 16
    end
end
for _, plr in Runners do
	if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
		task.spawn(function()
			plr.Character.HumanoidRootPart.CFrame = Teleports.Course_Spawns:GetChildren()[math.random(1, #Teleports.Course_Spawns:GetChildren())].CFrame
			plr.Character.Humanoid.WalkSpeed = 0
			
			task.wait(3)
			
			plr.Character.Humanoid.WalkSpeed = 16
		end)
		
	end
end

1 Like