Function isn't firing while the argument is true

The function isn’t firing while the attribute is true.

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char.Humanoid
		humanoid:SetAttribute("Infected", false)
		while true do
			humanoid:GetAttributeChangedSignal("Infected"):Connect(function(attribute)
				if attribute then
					print("aaaaa")
					createInfected(char, plr)
				else
					print(false)
					for i, v in pairs(infected) do
						if v.Name == plr.Name then
							table.remove(infected, i)
						end
					end
				end
			end)
			task.wait()
		end
	end)
end)

There’s no need for a while loop here, that’s just eating up memory. Get attribute changed signal automatically detects for changes and then runs the code without needing to loop.

I forgot to say that was just for testing.

Ok, well remove that, then if it’s still doesn’t work, print attribute

2 Likes

You stole my suggestion! Was just about to reply to print attribute.
Anyway it could also be helpful to print humanoid. Just to make sure.

2 Likes

It works now I will add a check in the function instead of the ChangedSignal.

1 Like