Server event attack only working one player at a time rather than all at once?

This is hard to explain in a title, but I have a button that one person in the server has access too and when they click it, it fires a remote event to the server to play an attack, in this case, a big hand will spawn in front of every player and flick them out of the map all at once.

My problem is that for some reason it only works half of the time and when it does work, it spawns the giant hand by each player and plays the full flick sequence one player at a time, rather than all players at once like I need.

Another note, this event will only effect players who are not the person who can press the button as well as not in the safe zone (there is a bool value in every player to check if they are in the safe zone or not).

Here is my script so far that controls the attack in ServerScriptService:

local rep = game:GetService("ReplicatedStorage")
local event = rep:FindFirstChild("ControlPanelEvents")
local models = rep:FindFirstChild("ControlModels")

	for i, v in pairs (game.Players:GetPlayers()) do
		if v.Name ~= rep.CurrentMaster.Value and v.Character:FindFirstChild("SafeZone").Value == false then
			------hm nothing
			v.Character.HumanoidRootPart.Anchored = true
			local flicker = rep.ControlModels:FindFirstChild("MightyF"):Clone()
			flicker.Parent = workspace
			flicker:MoveTo(, v.Character.HumanoidRootPart.Position.Y, v.Character.HumanoidRootPart.Position.Z + 4))
			flicker.One.Transparency = 1
			flicker.Two.Transparency = 0
			--play sound
			v.Character.HumanoidRootPart.Anchored = false
			local BodyVelocity ="BodyVelocity", v.Character.HumanoidRootPart)
			BodyVelocity.Velocity =,math.huge^math.huge,-math.huge^math.huge)
			BodyVelocity.MaxForce =,50000,-50000)
			--remove and die
			v.Character.Humanoid.Health = -500

Because it hasn’t finished to one player. A loop can be in order, but it is always synchronous. That’s why when you do a numerical loop, it goes in order but doesn’t print at the same time.

To fix your problem, just put a coroutine.wrap() after the for i,v in pairs....


Wow I never knew about coroutines, it works perfectly! Thank you!

1 Like