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

Why is this not detecting that seekers is equal to players?

This code is meant to print something when the amount of seekers is equal to the amount of players, however it doesn't, even though it says that they are equal.

Code that checks how many players are seekers:

activeseekers = 0
currentseekers = coroutine.create(function()
	while true do wait(.5)
		for i,v in pairs(plrs:GetChildren()) do
			if v.Character:FindFirstChild("Seeker") then
				if v.Character.Seeker.Value == true then
					activeseekers = activeseekers + 1
				else
				end
			end
		end
		print("ACTIVE SEEKERS: ".. activeseekers)
		print("ACTIVE PLAYERS: ".. playersplaying)
		activeseekers = 0
	end
end)
coroutine.resume(currentseekers)

It prints active seekers and players are equal when the seeker touches a hider, but the following code doesn't detect that they are equal;

clearmap = coroutine.create(function()
	while true do
		wait(.01)
		if activeseekers == playersplaying and playersplaying >= 1 then
			print("All players found!")
		end
	end
end)
coroutine.resume(clearmap)

Why isn't it working?

1 answer

✓ Accepted answer

Probably because you set activeseekers back to 0 after printing.

local activeseekers = 0
local currentseekers = coroutine.create(function()
    while wait(.5) do
        activeseekers = 0
        for i,v in pairs(plrs:GetPlayers()) do
            if v.Character and v.Character:FindFirstChild("Seeker") and v.Character.Seeker.Value == true then
                activeseekers = activeseekers + 1
            end
        end
        print("ACTIVE SEEKERS: ".. activeseekers)
        print("ACTIVE PLAYERS: ".. playersplaying)
        if activeseekers == playersplaying and playersplaying >= 1 then
            print("All players found!")
        end
    end
end)
coroutine.resume(currentseekers)

Though you shouldn't loop check for a BoolValue in their character just to see if they are a seeker. Instead, store all seekers in a table and then upon adding a new seeker, check if the length of the table equals all playing players.

3 comments

0

I set it back to 0 because otherwise it would stack.

0

How would I make a table and update it when a there's a new seeker?

0

Okay I figured it out

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