How to FireAllClients that has a specific attribute?

just as writen how can i fire all the clients that has a specific attribute ??
right now i fire just one client that has that specific attribute

for innocentsCounter, Innocents in pairs(playersinsession) do

	if Innocents:GetAttribute("Innocent") == true and Innocents:GetAttribute("Killer") == false then

		game.ReplicatedStorage.GameplayEvents.MorpherCutscene:FireAllClients(Innocent)


		end
		
	
	end

any help

You have already looped through all the players in the session and you have checked for their “Innocent” attribute. Now, rather than firing to ALL the clients, you just need to fire to the “Innocents” client, since it meets all your criteria. Change “FireAllClients” to “FireClient” and you should be set!

1 Like

i will try that even tho i have done this and it only fires a player each time not all at the same time but anyways i will still try the solution

1 Like

If it’s not firing to all the clients at the same time, that means there could be a function within your for loop that is yielding. Is there more to this code that you have taken out?

well i got tweens if that is considered a functions and as i expected the code didnt fire all the clients at the same time it waited for the fired client to finish and then fire the other

edited because i forgot something

the tweens arent in a function it is just a tween:Play()

1 Like

Try wrapping the code within your for loop within a task.spawn, which basically runs functions within your for loop simultaneously.

for innocentsCounter, Innocents in pairs(playersinsession) do
    task.spawn(function()
        if Innocents:GetAttribute("Innocent") == true and Innocents:GetAttribute("Killer") == false then
		    game.ReplicatedStorage.GameplayEvents.MorpherCutscene:FireAllClients(Innocent)
		end
        -- EVERYTHING ELSE YOU HAVE
	end)
end
1 Like

ok i will try this hopefully it will work

1 Like

it worked but i have a problem but i think that is from my script so anyways thanks

the problem is that it for some reason fires all the clients even for the ones who have the “Killer” attribute to true

1 Like

If the player is innocent, then no need to check for :GetAttribute(“Killer”). However, if you want to, you can change your conditional statement to:

if Innocents:GetAttribute("Innocent") == true and not Innocents:GetAttribute("Killer") then

This will account for players who have the “Innocent” attribute and either DON’T HAVE the “Killer” attribute or the “Killer” attribute is set to false. The “not” keyword checks BOTH for whether the attribute is nil or false!

1 Like

no i dont need to other statement so i will just simply remove it i even had the thought this would be the problem but ill try it

1 Like

it didnt work sadly for some reason…

Fire all clients or fire client?

Within your OnClientEvent Connection, check if the Player has the Attribute so:

Event.OnClientEvent:Connect(function(plr)
   if plr:GetAttribute("Example") then
      -- code
   end
end)

and when firing:

for _,plr in playersinsession do
Event:FireClient(plr) -- This should still fire for all Players but checking their attributes
end

1 Like

a nice simple solution is always the best THANK YOU

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.